如何设置圆角,不要剪辑子视图

时间:2013-07-05 09:03:11

标签: ios uibutton subview cliptobounds

我在图像底部做了一个按钮丝毫小箭头。

enter image description here

但我要添加圆角。这是我的问题。如果我添加圆角,那么我的按钮是掩码到边界,箭头是掩盖。如果我设置setMasksToBounds:NO则按钮不会被逼入。

+ (UIButton*)MCustomButtonSelected:(UIButton*)button andColor:(UIColor*)color shadowColor:(UIColor *)shadowColor andFontSize:(int)fontSize numberOfLines:(int)lines{

button.titleLabel.numberOfLines = lines;
UIImage * radialGradient = [Color getRadialGradientImage:button.frame.size centre:CGPointMake(0.5, 0.6) radius:1.4 startColor:color endColor:shadowColor];
[button setBackgroundColor:[UIColor colorWithPatternImage:radialGradient]];
[button.layer setBorderColor:[[UIColor clearColor] CGColor]];
button.layer.cornerRadius = 5;
[button.layer setMasksToBounds:NO];       // here is the problem 
[button.layer setOpaque:NO];
[button.titleLabel setTextAlignment:NSTextAlignmentCenter];
[button.titleLabel setFont:[UIFont fontWithName:[Fonts mainFontName] size:fontSize]];
button.titleLabel.adjustsFontSizeToFitWidth = YES;
[button.titleLabel setShadowOffset:CGSizeMake(0.5, 0.5)];
[button setTitleShadowColor:[Color buttonNormalTextShadowColor] forState:UIControlStateNormal];
[button setTitleColor:[Color buttonNormalTextColor] forState:UIControlStateNormal];
[button setTitleShadowColor:[Color buttonPressTextShadowColor] forState:UIControlStateHighlighted];
[button setTitleColor:[Color buttonPressTextColor] forState:UIControlStateHighlighted];

CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI_4);
UIView * pointer = [[UIView alloc]initWithFrame:CGRectMake(button.frame.size.width/2-5, button.frame.size.height-5, 10, 10)];
pointer.backgroundColor = color;
pointer.transform = transform;
pointer.tag = 10;
pointer.clipsToBounds = NO;

[button addSubview:pointer];
[button sendSubviewToBack:pointer];
return button;
}

任何人都可以帮助我。

1 个答案:

答案 0 :(得分:0)

这样做:

UIBezierPath *path = "create a path representing ur desired shape, along with the arrow"
CAShapeLayer *shape = [CAShapeLayer layer];
shape.path = path.CGPath;

button.layer.mask = shape;