gpt4 book ai didi

iphone - UIButton类型RoundedRect的框架

转载 作者:行者123 更新时间:2023-12-03 20:22:05 24 4
gpt4 key购买 nike

对于 UIButton,我使用的是第一个 UIButtonTypeCustom,现在我想将其更改为 RoundedRect,但是当我将 UIButtonTypeCustom 更改为 UIButtonTypeRoundedRect 时,它会显示白色的 RoundedRect,而不是为其指定的颜色,而且它还会显示 roundedrect 按钮后面的矩形按钮框架的边缘。所以我想知道如何解决这个问题。

UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

[myButton addTarget:self action:@selector(dismissView:) forControlEvents:UIControlEventTouchUpInside];

myButton.frame = CGRectMake(0, 0, 60, 30);

[myButton setTitle:@"Done" forState:UIControlStateNormal];

myButton.backgroundColor = [UIColor colorWithHue:1.0/12 saturation:2.0/3 brightness:4.0/10 alpha:1.0];

UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithCustomView:myButton];

[[self navigationItem] setLeftBarButtonItem:button animated:YES];

感谢您的帮助。

最佳答案

嗯...如果 UIButtonUIButtonTypeRoundedRect,恐怕无法更改它的背景颜色。

我的建议是创建一个 UIButtonTypeCustom 并更改其图层以模仿 UIButtonTypeRoundedRect

试试这个代码:

#import <QuartzCore/QuartzCore.h>

[myButton.layer setMasksToBounds:YES];
[myButton.layer setCornerRadius:10.0f];
[myButton.layer setBackgroundColor:[UIColor whiteColor].CGColor;

关于iphone - UIButton类型RoundedRect的框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9022663/

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