美文网首页
UILabel,UIAlertview自定义

UILabel,UIAlertview自定义

作者: 未来可期me | 来源:发表于2018-04-09 15:59 被阅读8次
    #import <UIKit/UIKit.h>
    
    @interface DGLabel : UILabel
    
    @property (nonatomic, assign) UIEdgeInsets textInsets; // 控制字体与控件边界的间隙
    
    @end
    
    
    #import "DGLabel.h"
    
    @implementation DGLabel
    
    - (instancetype)init {
        if (self = [super init]) {
            _textInsets = UIEdgeInsetsZero;
        }
        return self;
    }
    
    - (instancetype)initWithFrame:(CGRect)frame {
        if (self = [super initWithFrame:frame]) {
            _textInsets = UIEdgeInsetsZero;
        }
        return self;
    }
    
    - (void)drawTextInRect:(CGRect)rect {
        [super drawTextInRect:UIEdgeInsetsInsetRect(rect, _textInsets)];
    }
    
    @end
    
    
    #import <UIKit/UIKit.h>
    
    @interface DGAlertView : UIAlertView
    
    
    - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;
    
    @end
    
    #import "DGAlertView.h"
    
    @implementation DGAlertView
    
    /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    - (void)drawRect:(CGRect)rect {
        // Drawing code
    }
    */
    
    - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated{
        if (buttonIndex == 0) {
            //[super dismissWithClickedButtonIndex:buttonIndex animated:animated]; // 消失
        }else{
            // ...
            // 不消失
        }
    }
    
    
    @end
    
    if ([responseObject[@"ios"][@"is_forced_update"] integerValue]) {//是否强制更新
                    DGAlertView *alert = [[DGAlertView alloc]initWithTitle:@"发现新版本"
                                                                   message:nil
                                                                  delegate:self
                                                         cancelButtonTitle:nil
                                                         otherButtonTitles:@"立即更新", nil];
                    alert.tag = 3;
                    DGLabel *textLabel = [[DGLabel alloc] init];
                    textLabel.font = [UIFont systemFontOfSize:13];
                    textLabel.numberOfLines =0;
                    textLabel.textAlignment =NSTextAlignmentLeft;
                    textLabel.textInsets = UIEdgeInsetsMake(0.f, 10.f, 0.f, 10.f); // 设置左内边距
                    textLabel.text = responseObject[@"ios"][@"content"];
                    [alert setValue:textLabel forKey:@"accessoryView"];
                    [alert show];
                }else {
                    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"已存在最新版本"
                                                                   message:latestVersion
                                                                  delegate:self
                                                         cancelButtonTitle:@"忽略"
                                                         otherButtonTitles:@"更新", nil];
                    alert.tag = 2;
                    [alert show];
                }
    

    相关文章

      网友评论

          本文标题:UILabel,UIAlertview自定义

          本文链接:https://www.haomeiwen.com/subject/eyuihftx.html