日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

轻松使用富文本

發布時間:2023/12/9 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 轻松使用富文本 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最后發現需要6.0以后,因為nsfontattributename之類的是6.0以后的api

? ? 長久以來,我以為富文本是一種在ios中使用特別麻煩的事情,但是不經意的研究發現,其實并沒有那么難!

? ?以下的代碼實現了uilabel中放置富文本。


NSMutableAttributedString *richTask = [[NSMutableAttributedString alloc] initWithString:task];NSDictionary *urgentAttributes = @{NSFontAttributeName : [UIFont fontWithName:@"Courier" size:24],NSStrokeWidthAttributeName : @3.0,NSStrokeColorAttributeName:[UIColor greenColor]};[richTask setAttributes:urgentAttributes range:urgentRange];





- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {NSString *identifier = nil;NSString *task = [self.tasks objectAtIndex:indexPath.row];NSRange urgentRange = [task rangeOfString:@"URGENT"];if (urgentRange.location == NSNotFound) {identifier = @"plainCell";} else {identifier = @"attentionCell";}UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];// Configure the cell...UILabel *cellLabel = (UILabel *)[cell viewWithTag:1];NSMutableAttributedString *richTask = [[NSMutableAttributedString alloc] initWithString:task];NSDictionary *urgentAttributes = @{NSFontAttributeName : [UIFont fontWithName:@"Courier" size:24],NSStrokeWidthAttributeName : @3.0,NSStrokeColorAttributeName:[UIColor greenColor]};[richTask setAttributes:urgentAttributes range:urgentRange];if (urgentRange.location != NSNotFound) {NSRange otherPartRange = NSMakeRange(urgentRange.length+urgentRange.location, task.length-urgentRange.length);NSDictionary* otherPartAttributes = @{NSFontAttributeName : [UIFont fontWithName:@"Courier" size:12],NSStrokeWidthAttributeName : @0,NSStrokeColorAttributeName:[UIColor redColor]};[richTask setAttributes:otherPartAttributes range:otherPartRange];}cellLabel.attributedText = richTask;return cell; }

轉載于:https://blog.51cto.com/derkin2jessie/1246321

總結

以上是生活随笔為你收集整理的轻松使用富文本的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。