IOS学习(一) 使用NSMutableAttributedString样式文本

来源:互联网 发布:xampp启动不了apache 编辑:程序博客网 时间:2024/05/02 01:38

呃 不会上传本地图片啊 伤啊伤啊伤..........


今天看了看样式文本,正好自己的项目也有用到,简单写了一个Demo,留存一下~~~


代码如下:


/** *  根据按钮Title设定Label文字 */- (IBAction)buttonPressed:(UIButton *)sender {    NSString *title = [sendertitleForState: UIControlStateNormal];    NSString *plainText = [NSStringstringWithFormat: @"%@ button pressed", title];//    _statusLabel.text = plainText; // 将按钮文本显示在Label上.        //  使用样式文本 NSMutableAttributedString    NSMutableAttributedString *styledText = [[NSMutableAttributedStringalloc] initWithString: plainText];    //  用于保存字符串属性 NSFontAttributeName可为属性字符串的一部分设定字体.字体大小与当前使用字体大小一致.    NSDictionary *attributes =@{NSFontAttributeName: [UIFontboldSystemFontOfSize: _statusLabel.font.pointSize]};    //  需要着重显示的内容范围    NSRange nameRange = [plainText rangeOfString: title];    [styledText setAttributes: attributes range: nameRange];    _statusLabel.attributedText = styledText;}


0 0
原创粉丝点击