HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何在ios中的UIAlertView上以普通字体显示所有按钮文本大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的iOSproject中,我有一个带有3个按钮的UIAlertView,但最后一个按钮文本认为粗体字体,如此…,如何将第三个按钮文本的字体样式设置为正常?

以下是用于创建该警报视图的代码

UIAlertView *alert = [[UIAlertView alloc]initWithtitle:@"test" message:@"testTestTest" delegate:Nil cancelButtontitle:nil otherButtontitles:@"first",@"second",@"third",nil];
    [alert show];

解决方法

我花了一些时间在这上面,并在UIAlertView呈现时去挖掘当前视图控制器的子视图结构.我能够显示所有按钮文本的正常字体.

我创建了UIAlertView的子类:

文件

#import <UIKit/UIKit.h>

@interface MLKLoadingAlertView : UIAlertView

- (id)initWithtitle:(NSString *)title;

@end

实施档案:

#import "MLKLoadingAlertView.h"

#define ACTIVITY_INDicATOR_CENTER   CGPointMake(130,90)

@implementation MLKLoadingAlertView

- (id)initWithtitle:(NSString *)title
{
    if ( self = [super init] )
    {
        self.title = title;
        self.message = @"\n\n";
        [self addButtonWithtitle:@"OK"];
        [self addButtonWithtitle:@"Cancel"];
        [self addButtonWithtitle:@"Sure"];

        [self setDelegate:self];
    }

    return self;
}

// You can Customise this based on your requirement by adding subviews.
- (void)didPresentAlertView:(UIAlertView *)alertView
{
    NSArray *subviews = [UIApplication sharedApplication].keyWindow.rootViewController.presentedViewController.view.subviews;

    if( subviews.count > 1 )
    {
        // iOS while presenTing an alertview uses a presening view controller. That controller's view has several subviews. I have picked one
        // subview from it which has frame SIMILAR TO the alertview frame.
        UIView *presentedView = [subviews objectATindex:1];

        for( UIView *view in presentedView.subviews )
        {
            for( UIView *subView in view.subviews )
            {
                if( [subView isKindOfClass:[UITableView class]] )
                {
                    NSInteger numberOfButtons = [(UITableView *)subView numberOfRowsInSection:0];
                    UITableViewCell *buttonCell = [(UITableView *)subView cellForRowATindexPath:[NSIndexPath indexPathForRow:numberOfButtons-1 inSection:0]];


                    for( UIView *cellSubView in buttonCell.contentView.subviews )
                    {
                        if( [cellSubView isKindOfClass:[UILabel class]] )
                        {
                            [(UILabel *)cellSubView setFont:[UIFont systemFontOfSize:17]];
                        }
                    }

                    break;
                }
            }
        }

        UIActivityInDicatorView *customActivityInDicator = [[UIActivityInDicatorView alloc] initWithActivityInDicatorStyle:UIActivityInDicatorViewStyleGray];
        [customActivityInDicator startAnimaTing];
        customActivityInDicator.center = ACTIVITY_INDicATOR_CENTER;

        [presentedView addSubview:customActivityInDicator];
    }
}

我在我的View Controller中创建了这个MLKLoadingAlertView的实例,如下所示:

@H_982_4@mLKLoadingAlertView *loadingAlertView = [[MLKLoadingAlertView alloc] initWithtitle@R_143_6964@]; [loadingAlertView show];

这将显示以下输出

使用这种方法我们可以实现两件事:

>我们可以在iOS 7中为UIAlertView添加子视图
>我们可以在iOS 7中更改按钮文本的字体

注意:此方法仅适用于iOS 7.

大佬总结

以上是大佬教程为你收集整理的如何在ios中的UIAlertView上以普通字体显示所有按钮文本全部内容,希望文章能够帮你解决如何在ios中的UIAlertView上以普通字体显示所有按钮文本所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。