Raf*_*fAl 98
我正在使用自动布局.为我工作溶液设置UIButton的contentEdgeInsets.
button.contentEdgeInsets = UIEdgeInsetsMake(0.0f, 30.0f, 0.0f, 30.0f);
Run Code Online (Sandbox Code Playgroud)
button.contentEdgeInsets = UIEdgeInsets(top: 0.0, left: 30.0, bottom: 0.0, right: 30.0)
Run Code Online (Sandbox Code Playgroud)
小智 22
好的,到目前为止我找到的最简单的解决方案是:
self.textAlignment = UITextAlignmentCenter;
[self sizeToFit];
CGRect frame = self.frame;
frame.size.width += 20; //l + r padding
self.frame = frame;
Run Code Online (Sandbox Code Playgroud)
不完全是我想要的,但它确实有效.
Gir*_*hai 17
要在uibutton文本中设置填充,您需要使用UIButton的UIButton属性.在Storyboard中,要设置内容插入,请执行以下步骤: -
要向UILabel添加填充,最灵活的方法是子类化UILabel并添加edgeInsets属性.然后,您可以设置所需的插图,并相应地绘制标签.
OSLabel.h
#import <UIKit/UIKit.h>
@interface OSLabel : UILabel
@property (nonatomic, assign) UIEdgeInsets edgeInsets;
@end
Run Code Online (Sandbox Code Playgroud)
OSLabel.m
#import "OSLabel.h"
@implementation OSLabel
- (id)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
self.edgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
}
return self;
}
-(id)initWithCoder:(NSCoder *)aDecoder{
self = [super initWithCoder:aDecoder];
if(self){
self.edgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
}
return self;
}
- (void)drawTextInRect:(CGRect)rect {
return [super drawTextInRect:UIEdgeInsetsInsetRect(rect, self.edgeInsets)];
}
@end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
54131 次 |
| 最近记录: |