V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
xi_lin
V2EX  ›  iDev

在模拟器中选中 `Color Blended Layers`后 UILabel 被标记为红色

  •  
  •   xi_lin · 2016-01-20 17:22:47 +08:00 · 5145 次点击
    这是一个创建于 3021 天前的主题,其中的信息可能已经有所发展或是发生改变。
    这些被标记为红色的 UILabel 可以确定 backgroundColor 是 whiteColor 或者 redColor ,而且 opaque 没有被修改,是 YES

    还会有什么设置导致这个问题不?
    第 1 条附言  ·  2016-01-21 00:13:02 +08:00

    在开启Color Blended Layers之后,notifyDateLabel是绿色的,其他几个 label 都是红色的。

    - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
        if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
            self.senderNameLabel = [UILabel mt_labelWithFont:FONT(17) andColor:COLOR_NAV_TITLE];
            self.senderNameLabel.backgroundColor = [UIColor whiteColor];
            [self.contentView addSubview:self.senderNameLabel];
    
            self.actionTextLabel = [UILabel mt_labelWithFont:FONT(15) andColor:COLOR_NAV_TITLE];
            self.actionTextLabel.numberOfLines = 5;
            self.actionTextLabel.backgroundColor = [UIColor whiteColor];
            [self.contentView addSubview:self.actionTextLabel];
    
            self.notifyDateLabel = [UILabel mt_labelWithFont:FONT(12) andColor:COLOR_NAV_TITLE];
            self.notifyDateLabel.backgroundColor = [UIColor whiteColor];
            [self.contentView addSubview:self.notifyDateLabel];
    
            [self setLayoutConstraints];
        }
        return self;
    }
    
    第 2 条附言  ·  2016-01-21 00:13:26 +08:00
    - (void)setLayoutConstraints {
        CGFloat offsetX = 70;
        CGFloat offsetY = 15;
        CGFloat maxWidth = SCALE_WITH_RATIO(180);
        [self.senderNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
          make.left.equalTo(self.contentView).offset(offsetX);
          make.top.equalTo(self.contentView).offset(offsetY);
          make.width.mas_lessThanOrEqualTo(maxWidth);
        }];
    
        offsetY = 12.5;
        maxWidth = SCALE_WITH_RATIO(180);
        [self.actionTextLabel mas_makeConstraints:^(MASConstraintMaker *make) {
          make.top.equalTo(self.senderNameLabel.mas_bottom).offset(offsetY);
          make.left.equalTo(self.senderNameLabel);
          make.width.mas_lessThanOrEqualTo(maxWidth);
        }];
    
        offsetY = 10;
        CGFloat bottomOffsetY = -15;
        [self.notifyDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
          make.top.equalTo(self.actionTextLabel.mas_bottom).offset(offsetY);
          make.left.equalTo(self.senderNameLabel);
          make.bottom.equalTo(self.contentView).offset(bottomOffsetY);
        }];
    }
    
    - (void)prepareForReuse {
        [super prepareForReuse];
    
        self.senderNameLabel.text = nil;
        self.actionTextLabel.text = nil;
        self.notifyDateLabel.text = nil;
    }
    
    - (void)updateWithMessageModel:(MTUserMessageModel *)model {
        self.senderNameLabel.text = model.senderName;
        self.actionTextLabel.text = model.actionText;
        self.notifyDateLabel.text = model.notifyDate;
    }
    

    里面用到的 label 生成方法如下

    + (UILabel *)mt_labelWithFont:(UIFont *)font andColor:(UIColor *)color {
        UILabel *label = [UILabel new];
        label.font = font;
        label.textColor = color;
        return label;
    }
    
    第 3 条附言  ·  2016-01-21 10:24:07 +08:00
    补个截图
    第 4 条附言  ·  2016-01-21 10:51:38 +08:00
    6 条回复    2016-01-21 10:49:11 +08:00
    huoshanhui
        1
    huoshanhui  
       2016-01-20 22:38:42 +08:00
    贴代码看看?
    xi_lin
        2
    xi_lin  
    OP
       2016-01-21 00:13:36 +08:00
    @huoshanhui 已更新代码
    huoshanhui
        3
    huoshanhui  
       2016-01-21 10:03:09 +08:00
    奇怪,几乎一模一样的操作。
    xi_lin
        4
    xi_lin  
    OP
       2016-01-21 10:17:43 +08:00
    @huoshanhui 是啊。。
    lee0100317
        5
    lee0100317  
       2016-01-21 10:37:56 +08:00   ❤️ 1
    应该是无解 中文都会这样 纯英文不会
    xi_lin
        6
    xi_lin  
    OP
       2016-01-21 10:49:11 +08:00
    @lee0100317 试了下英文还真是。。原来如此,感谢!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5559 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 07:21 · PVG 15:21 · LAX 00:21 · JFK 03:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.