[英]IOS 6 and Auto Layout custom button height wrong
我创建了一个非常简单的自定义平面按钮:
@implementation HAFlatButton
+ (id)buttonWithColor:(UIColor *)aColor
{
id button = [super buttonWithType:UIButtonTypeCustom];
[button setFlatColor:aColor];
CGRect frame = [button frame];
frame.size.height = 200;
[button setFrame:frame];
return button;
}
+ (id)defaultButton
{
return [HAFlatButton buttonWithColor:[HAColors buttonColor]];
}
- (void)setFlatColor:(UIColor *)flatColor
{
_flatColor = flatColor;
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect {
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = UIGraphicsGetCurrentContext();
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:4.0];
CGContextSaveGState(context);
[path addClip];
[_flatColor setFill];
CGContextFillRect(context, rect);
CGColorSpaceRelease(colorSpace);
}
@end
当我使用[HAFlatButton defaultButton]将按钮添加到我的自动布局中时,它刚好比按钮文本高,但是当我在我的布局中添加[UIButton buttonWithType:UIButtonTypeRoundedRect]时,它在标签周围具有适当的插图。
我究竟做错了什么?
您需要执行以下一项或多项操作:
添加高度限制。
覆盖internalSize返回值。
调整垂直内容的优先级。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.