gpt4 book ai didi

IOS 6 和 Auto Layout 自定义按钮高度错误

转载 作者:行者123 更新时间:2023-11-29 13:08:16 25 4
gpt4 key购买 nike

我创建了一个非常简单的自定义平面按钮:

@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] 时,它在标签周围有适当的插入.

我做错了什么?

最佳答案

您需要执行以下一项或多项操作:

添加高度限制。

覆盖 intrinsicSize 返回值。

调整垂直内容拥抱优先级。

关于IOS 6 和 Auto Layout 自定义按钮高度错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18027378/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com