美文网首页iOS技术
UILabel设置内边距

UILabel设置内边距

作者: 梦想家家家 | 来源:发表于2017-06-09 03:52 被阅读255次

CustomLabel.h

#import

@interface CustomLabel : UILabel

@property (nonatomic, assign) UIEdgeInsets textInsets; // 控制字体与控件边界的间隙

@end

CustomLabel.m

#import "CustomLabel.h"

@implementation CustomLabel

- (instancetype)init {

if (self = [super init]) {

_textInsets = UIEdgeInsetsZero;

}

return self;

}

- (instancetype)initWithFrame:(CGRect)frame {

if (self = [super initWithFrame:frame]) {

_textInsets = UIEdgeInsetsZero;

}

return self;

}

- (void)drawTextInRect:(CGRect)rect {

[super drawTextInRect:UIEdgeInsetsInsetRect(rect, _textInsets)];

}

@end

Demo.m

CustomLabel *titleLabel    = [[CustomLabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.f, 24.0f)];

titleLabel.backgroundColor = [UIColor whiteColor];

titleLabel.textColor      = [UIColor blackColor];

titleLabel.font            = [UIFont systemFontOfSize:12.0f];

titleLabel.textInsets      = UIEdgeInsetsMake(0.f, 15.f, 0.f, 0.f); // 设置左内边距

相关文章

  • UILabel设置内边距

    CustomLabel.h #import @interface CustomLabel : UILabel @p...

  • iOS UILabel设置内边距

    有时候我们希望可以设置UILabel的内边距,为了解决这个问题,设计MarginLabel如下,继承自UILabe...

  • uilabel 内边距

    重写一个方法 - (void)drawTextInRect:(CGRect)rect { UIEdgeInsets...

  • iOS给UILabel增加内边距

    UILabel默认不带内边距,调整内边距步骤: 1.制定一个空白区:UIEdgeInsets。 2. 重写draw...

  • iOS-设置UILabel的内边距

    问题说明 默认Label的显示效果如下 很多情况下,需要如下有内边距的效果(注意第一行与最后一行文字与label的...

  • UILabel内边边距

    在开发过程中,简单的使用UILabel属性,不能够达到我们显示一些特殊的要求。UILabel要显示边框时,不像UI...

  • uilabel改变内边距

    .h 直接代码 .m

  • 前端Day11

    CSS内边距 内边距是设置盒子与子盒子之间的距离。 pading: 10px; 设置上下左右都是10px的内边距。...

  • Android TextView边界表情显示不全

    试试给TextView是设置 内边距,我这边竟然可以了。 设置右侧内边距 30dp

  • UITextView

    设置UITextView 内边距

网友评论

    本文标题:UILabel设置内边距

    本文链接:https://www.haomeiwen.com/subject/kldxqxtx.html