gpt4 book ai didi

ios - 如何在 iOS sdk 中的 UIButton 内添加边框?

转载 作者:行者123 更新时间:2023-11-29 10:45:37 30 4
gpt4 key购买 nike

我正在使用以下代码为 UIButton 添加边框,它工作正常,但边框出现在 UIButton 区域之外。如何在 UIbutton 区域内添加边框。请帮助我..

[[button1 layer] setBorderWidth:7.0];

[[button1 layer] setBorderColor:[UIColor redColor].CGColor];

最佳答案

没有直接的方法可以为 UIView 添加内边框。但是,您可以向其添加 subview 。像这样:(在您的 .m 文件中实现以下方法)。

-(void)setInnerBorderFor:(UIView *)aView withFloatVal:(CGFloat)aFloatVal
{
UIView *borderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, aView.frame.size.width, aView.frame.size.height)];
borderView.backgroundColor = [UIColor clearColor];
borderView.layer.borderWidth = aFloatVal;
borderView.layer.borderColor = [UIColor blackColor].CGColor;
[aView addSubview:borderView];

}

然后,您可以调用:

[self setInnerBorderFor:button1 withFloatVal:7.0f];

关于ios - 如何在 iOS sdk 中的 UIButton 内添加边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22503731/

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