富文本

//dom

//  ViewController.m性能

//  富文本測試

//字體

//  Created by dc008 on 16/1/7.網站

//  Copyright © 2016 cxy. All rights reserved.ui

//spa


#import "ViewController.h".net


@interface ViewController (){3d

    int num;orm

}


@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    num = 0;

    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 375, 667)];

//    label.backgroundColor = [UIColor lightGrayColor];

    label.numberOfLines = 0;//多行

//    label.textAlignment = NSTextAlignmentLeft;//對齊方式

//    label.text = @"今每天氣好冷啊";

    //建立可變屬性字符串

    NSString *str = @"       所以按照常規估計,像 iOS 9.2.1 這種小版本的更新通常都是以改進系統性能與功能完善爲主。而從一些已經更新使用過的用戶反饋來看,很多像控制中心和狀態欄出現的掉幀和異常現象都已經被修復。不過也有用戶反映,設備的耗電量彷佛有所增長。\n       至於很多中國國內用戶想了解的,Apple Pay 如今是否能添加銀行卡與信用卡等,從目前已更新完畢用戶發佈的信息來看,應該是還沒開始實現這項功能,不過按照蘋果如今的動向來看,相信也不會過久了。如今還沒收到 iOS 9.2.1 beta 2 升級提醒的用戶,能夠刷新設備的軟件更新選項,應該就能夠收到版本更新通知。或者也能夠到蘋果開發者中心官方網站下載固件更新。此次升級的容量很是小,才 34.6M 左右,10 來分鐘就能夠更新完畢。\n       按照國外媒體掌握的情報來看,iOS 9.2.1 應該是 3 月發佈會以前蘋果最後測試的一個 iOS 系統版本,在完成以後就會直接升級到 iOS 9.3,並將之做爲傳聞中 4 英寸新 iPhone 的運行系統。而對於這個情報的來源,目前咱們還沒法確認真僞。\n";

    NSMutableAttributedString *text = [[NSMutableAttributedString alloc]initWithString:str];

    for (int i = 0; i < [text length]; i++) {

        float sui = arc4random()%256/255.0;

        float sui1 = arc4random()%256/255.0;

        float sui2 = arc4random()%256/255.0;

        NSString *strTwo = [str substringWithRange:NSMakeRange(i, 1)];

        if ([strTwo isEqualToString:@"\n"]) {

            [text addAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithRed:sui green:sui1 blue:sui2 alpha:0.9]} range:NSMakeRange(num, i - num)];

        num =i;

        }

       

    }

    NSLog(@"%ld",[text length]);

    //設置某個區域的字體大小

//    [text addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:40] range:NSMakeRange(7, 1)];

    //增長下劃線 刪除線 字體顏色

//    [text addAttributes:@{NSUnderlineStyleAttributeName : [NSNumber numberWithInteger:NSUnderlineStyleDouble],NSStrikethroughStyleAttributeName : [NSNumber numberWithInteger:50],NSForegroundColorAttributeName : [UIColor colorWithRed:0.4 green:0.5 blue:0.7 alpha:1]} range:NSMakeRange(0, 466)];

//    [text addAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithRed:0.5 green:0.2 blue:0.9 alpha:1]} range:NSMakeRange(0, 466)];

    

    label.attributedText = text;

    [self.view addSubview:label];

    self.view.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.5];

    

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end

相關文章
相關標籤/搜索