iOS學習,ios學習路線

來源:互聯網
上載者:User

iOS學習,ios學習路線

思路:

  1.new 一個 Empty 尾碼為 .txt 檔案,內容隨筆拷貝一段

  2.用 NSString 接收本地檔案,再用一個標題拼接字串

  3.建立一個 NSMutableParagraphStyle 執行個體,設定標題置中、標題距離本文間隔

  4.建立一個 NSMutableParagraphStyle 執行個體,設定本文靠左對齊、每段開頭縮排 10

  5.建立一個基礎動畫的執行個體,用代理監聽動畫結束

話不多說上代碼

#pragma mark -- 拼接字元- (void)loadData:(NSString *)filename {        //第一個段落    NSMutableParagraphStyle *first = [[NSMutableParagraphStyle alloc]init];    first.alignment = NSTextAlignmentCenter;    first.lineSpacing = 10;        //第二個段落    NSMutableParagraphStyle *second = [[NSMutableParagraphStyle alloc]init];    //從左開始寫    second.alignment = NSTextAlignmentLeft;    //首行縮排    second.firstLineHeadIndent = 10;    //間距    second.lineSpacing = 10;        UIFont *titleFont = [UIFont systemFontOfSize:16];    UIFont *contextFont = [UIFont systemFontOfSize:13];        NSMutableAttributedString *str1 = [[NSMutableAttributedString alloc]initWithString:@"遊戲許可及服務合約" attributes:@{NSParagraphStyleAttributeName:first,NSFontAttributeName:titleFont}];        //標題拼接本文,本文前加分行符號    NSString *str = [NSString stringWithFormat:@"\n%@",filename];        NSMutableAttributedString *str2 = [[NSMutableAttributedString alloc]initWithString:str attributes:@{NSParagraphStyleAttributeName:second,NSFontAttributeName:contextFont}];        [str1 appendAttributedString:str2];    _textView.attributedText = str1;}#pragma mark -- 關閉動畫- (void)closeAniamtion:(UIView *)view {    CABasicAnimation *animation = [CABasicAnimation animation];    animation.keyPath = @"transform.scale";    animation.toValue = @0.9;    animation.duration = 0.4;    animation.delegate = self;    animation.removedOnCompletion = NO;    animation.fillMode = kCAFillModeForwards;    [view.layer addAnimation:animation forKey:@"closeAnimation"];}#pragma mark -- 本地 txt 檔案內容- (NSString *)filename {    //本地 txt 檔案    NSString *path = [[NSBundle mainBundle]pathForResource:@"淺遇時光,靜好無恙.txt" ofType:nil];    //取出內容    NSString *filename = [[NSString alloc]initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];    return filename;}
#pragma mark -- 代理監聽動畫停止- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {    if ([_bgView.layer animationForKey:@"closeAnimation"] == anim) {        [_bgView removeFromSuperview];    }}

完整代碼在 github 上,點我下載

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.