[英]Setting Size of UIButton Independent of Content
我正在创建带有边框的UIButtons行,其标题将设置为不同的数字。 确实如此,所有按钮均根据内部文本的长度自行调整大小,但我希望它们的大小均相同,比容纳文本所需的大小大一点,因为这样看起来会更好。
我使用子类在按钮中添加了边框,在其中指定了以下内容:
self.layer.cornerRadius = 5.0;
self.layer.borderColor = UIColor.blackColor().CGColor
self.layer.borderWidth = 1
self.backgroundColor = UIColor.whiteColor()
self.tintColor = UIColor.blackColor()
有没有一种方法可以绝对地指定定义按钮周围边框的矩形的大小? 我尝试将self.frame设置为CGRect,但这似乎根本不影响边框。
您正在使用情节提要吗?
如果是,请按住Ctrl并将您的按钮拖动到另一个按钮,使其宽度相等。
如果您不使用情节提要:
constraint = [NSLayoutConstraint
constraintWithItem:myButton
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem: otherButton
attribute:NSLayoutAttributeWidth
multiplier:1.0f
constant:0];
让我知道你是否有任何麻烦
尝试uibutton的titleEdgeInsets属性。 此处提供文档: https : //developer.apple.com/library/ios/documentation/UIKit/Reference/UIButton_Class/#//apple_ref/occ/instp/UIButton/titleEdgeInsets
默认为零,这意味着它会适合
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.