gpt4 book ai didi

ios - 如何从 UIButton 控件中删除尖锐的矩形边缘?

转载 作者:可可西里 更新时间:2023-11-01 03:05:19 24 4
gpt4 key购买 nike

请看下图:

enter image description here

如您所见,边缘是尖锐的矩形,它们从圆角按钮中出来。我怎么能不显示边缘而只显示圆形按钮?

更新(解决方案):

我用下面的代码来实现圆角:

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.stopButton.bounds 
byRoundingCorners:UIRectCornerAllCorners
cornerRadii:CGSizeMake(12.0, 12.0)];

// Create the shape layer and set its path
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = self.stopButton.bounds;
maskLayer.path = maskPath.CGPath;
// Set the newly created shape layer as the mask for the image view's layer
self.stopButton.layer.mask = maskLayer;

新问题:

此代码在 startButtonRound.layer.cornerRadius 行中给出了错误。

  UIButton *roundStartButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
roundStartButton.frame = CGRectMake(10, 10, 100, 20);
[roundStartButton setBackgroundImage:[UIImage imageNamed:@"green_gradient.jpg"] forState:UIControlStateNormal];

roundStartButton.layer.cornerRadius = 12.0;
UIBarButtonItem *startButton = [[UIBarButtonItem alloc] initWithCustomView:roundStartButton];

最佳答案

你可以单独使用 CALayer 来做到这一点:

CALayer *myLayer = [CALayer layer];
[myLayer setMasksToBounds:YES];
[myLayer setCornerRadius:5.0f];
[myLayer setBorderWidth:1.0f];
[myLayer setBorderColor: [[UIColor blackColor] CGColor]];
[myLayer setBackgroundColor: [[UIColor whiteColor] CGColor]];

您还需要包含 QuartzCore 框架并在您自己的框架中包含框架 header 。

#include <QuartzCore/QuartzCore.h>

希望对你有帮助

蒂姆

关于ios - 如何从 UIButton 控件中删除尖锐的矩形边缘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6876761/

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