ios UILabel 缩进

UITestField 的缩进:

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 10.0, 30.0)];//左端缩进10像素
    view.backgroundColor = [UIColor clearColor];
    _textField.leftView = view;
    _textField.leftViewMode = UITextFieldViewModeAlways;

 

 

直接上代码:

NSMutableParagraphStyle *style =  [[NSParagraphStyle defaultParagraphStyle] mutableCopy] 
        style.alignment = textAlignment;  //对齐
        style.headIndent = 10;          //行首缩进
        style.firstLineHeadIndent = 10.0;//首行缩进
        style.tailIndent = -10.0;//行尾缩进
        
        NSAttributedString *attrText = [[NSAttributedString alloc] initWithString:@“阿萨德发阿萨德发舒服” attributes:@{ NSParagraphStyleAttributeName : style}];
        UILabel *label = [[UILabel alloc] init];
        label.attributedText = attrText;  //此时不用再设置label.text 了,在NSAttributedString *attrText初始化的时候已经设置了

你可能感兴趣的:(IOS)