gpt4 book ai didi

ios - 在 UIView 角上创建 mask

转载 作者:行者123 更新时间:2023-11-29 03:04:32 24 4
gpt4 key购买 nike

我已经构建了一个简单的开关按钮:

enter image description here

点击“A”或“C”时,红色中间部分会向左或向右移动。

但是正如你所看到的,我的圆角背景仍然是白色的。我如何得到的是在 View 上有一个清晰的 mask ?

这是我正在使用的代码:

- (id)init
{
self = [super init];
if (self) {
self = [[[NSBundle mainBundle]loadNibNamed:@"CategortSwitch" owner:self options:nil]objectAtIndex:0];

//Im making the backround color clear so this should not happen..

self.backgroundColor = [UIColor clearColor];
[self setup];
}
return self;
}

-(void)setup
{
self.backRoundView.layer.borderColor = [UIColor colorWithRed:223.0/255.0 green:94.0/255.0 blue:95.0/255.0 alpha:1].CGColor;
self.backRoundView.layer.borderWidth = 1.0;
self.backRoundView .layer.cornerRadius = 5.0;

//And the mask is set to YES:

self.backRoundView .layer.masksToBounds = YES;
self.backRoundView .layer.backgroundColor=[[UIColor clearColor] CGColor];
}

此外,当我向左或向右设置红色 View 的动画时,角点不会获得其所在的 UIView 的半径,角点将保持指向左侧或右侧的幻灯片权利。

最佳答案

如果您发布的代码是从 UIView 派生的对象,我猜白角来自 UIView 背景色。在 self.layer 而不是 self.backRoundView.layer 上设置边框。

你也可以设置 self.backgroundColor = [UIColor clearColor];但随后您需要将 self.backRoundView.backgroundColor 设置为 [UIColor whiteColor]。

关于ios - 在 UIView 角上创建 mask ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22934681/

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