iOS10 下划线不显示、导航栏上自定义视图不显示

(一) 在开发过程中发现10.3版本上下划线不显示:

在设置下划线的时候:

NSMutableAttributedString *newPrice = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@", tex]];
    [newPrice addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, newPrice.length)];

修改方案:
增加一个富文本属性: NSBaselineOffsetAttributeName : @(NSUnderlineStyleSingle)

    NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc] initWithString:tex];
    [attribtStr setAttributes:@{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle],   NSBaselineOffsetAttributeName : @(NSUnderlineStyleSingle)} range:NSMakeRange(0, tex.length)];

这样子就能正常显示啦

…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·…·

(二) 导航栏上自定义视图不显示:

创建视图

  UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:@"规则" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor colorWithHexString:@"555555"] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont customFontSize:14];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];

在其他版本度可以做正常显示,但是,在10.3版本上发现视图不见了。

解决方案:设置视图的frame 即可。
btn.frame = CGRectMake(0, 0, 80, 30);

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容