UILabel文字滚动、下划线

UILabel自定义文字,内增高,扩大padding

按钮button不会有这个问题,边框和文字之间本来就有间隙

增加Label的宽高

[self.promotionIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.equalTo(self).offset(12.5);
//        make.size.mas_equalTo(CGSizeMake(30, 13));
}];

- (void)setPromotionLabelText:(NSString *)text {
    self.promotionIcon.text = text;
    [self.promotionIcon sizeToFit];
    
    CGRect bounds = self.promotionIcon.bounds;
    [self.promotionIcon mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(bounds.size.width+5);
        make.height.mas_equalTo(bounds.size.height+4);
    }];
}
image

Label文字滚动

1、删除线

- (NSAttributedString *)makeTheAmountNumber:(NSString *)amountStr {
    NSString *lastStr = [NSString stringWithFormat:@"¥%@元", amountStr];
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:lastStr];
    [attributedString addAttributes:@{
                                      NSForegroundColorAttributeName : [UIColor darkGrayColor],
                                      NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle|NSUnderlinePatternSolid),
                                      NSStrikethroughColorAttributeName:[UIColor orangeColor]
                                      }
                     range:NSMakeRange(0, amountStr.length+1)];
    return attributedString.copy;
}

self.nameLabel.attributedText = [self makeTheAmountNumber:@"88.88"];
------------------------------------------------------------------------------------
NSAttributedString *attrStr = [[NSAttributedString alloc] initWithString:@"¥932452" attributes:@{
                                     NSFontAttributeName : [UIFont systemFontOfSize:20.f],
                                     NSForegroundColorAttributeName : [UIColor colorWithHexString:@"#5bcec0"],
                                     NSStrikethroughStyleAttributeName : @(NSUnderlineStyleSingle|NSUnderlinePatternSolid),
                                     NSStrikethroughColorAttributeName : [UIColor colorWithHexString:@"#5bcec0"]
                                     }];
添加的四个特征:
文字大小
文字颜色
删除线样式为单实线
删除线的颜色


2、通过sizeToFit改变frame——竖直排列

CGRect frame =CGRectMake(kScreenWidth/2,20,30,30);
UILabel *label = [[UILabel alloc] initWithFrame:frame];
label.backgroundColor = [UIColor orangeColor];
NSString*text = @"今天是个好日子啊";
label.text = text;
// 根据内容自适应尺寸
label.numberOfLines = 0;
[label sizeToFit];![Snip20180417_7.png](https://upload-images.jianshu.io/upload_images/185169-85e44fe7e44a6be0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

[self.view addSubview:label];
竖直排列
UILabel 竖直方向排列
1、换行
2、sizeToFit 自适应尺寸
没有numberOfLines
没有sizeToFit

3、文字滚动显示


参考资料

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容