调节一个多行Label之间的间隙

来源:互联网 发布:sql语句采用的编写语言 编辑:程序博客网 时间:2024/05/17 22:35

类方法是存放在这个类的元类结构中

类的方法是存放在这个类的元类结构中

yyivarinfo是封装成员变量的

yymethodinfo是封装方法的

yypropertyinfo是封装属性的

yyclassinfo这个类就是对我们常见的类进行一个二度封装OC中我们所有的类都继承自两个基类, NSObject 或者是  NSProxy(至今未还没见过)


因为类方法的效率更高些,所以一般不需要再方法内部访问成员变量的话,写个类方法还是好一些


比如调节一个多行Label之间的//
//  ViewController.m
//  TestParagraphLabel
//
//  Created by colawh on 16/10/30.
//  Copyright © 2016年 colawh. All rights reserved.
//

#import "ViewController.h"
#import "ParagraphLabel.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(100, 200, 100, 200)];
    label.numberOfLines = 0;
    [self.view addSubview:label];
    label.text = @"drawRect在以下情况下会被调用、如果在UIView初始化时没有设置rect大小,将直接导致drawRect不被自动调用。drawRect调用是在Controller->loadView, Controller->viewDidLoad 两方法之后掉用的.所以不用担心在控制器中,这些View的drawRect就开始画了.这样可以在控制器中设置一些值给View(如果这些View draw的时候需要用到某些变量值).";
    [label sizeToFit];
  label.attributedText =   [ViewController attributedStringWithString:label.text];
    // Do any additional setup after loading the view, typically from a nib.
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
+ (NSAttributedString *)attributedStringWithString:(NSString *)string{
    NSMutableParagraphStyle *paragraph  = [[NSMutableParagraphStyle alloc]init];
    paragraph.lineSpacing = 50;
    NSMutableAttributedString *touchString = [[NSMutableAttributedString alloc]initWithString:string];
    [touchString addAttribute:NSParagraphStyleAttributeName value:paragraph range:[string rangeOfString:string]];
    return touchString;
}

@end


0 0