我试图通过使按钮透明但仍带有边框的按钮来获得这种效果。当我制作透明图像时,由于某种原因,它们会使按钮变大。这是一些效果的例子。
在第一个图像中,导航栏上的按钮对导航栏的背景是半透明的。
在左侧的第二个图像中,“Action Composer”按钮是透明的,但仍带有边框。
最佳答案
试试这个:
这将创建一个透明按钮:
UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
button.frame GRectMake(x, y, w, h);
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Button" forState:UIControlStateNormal];
button.backgroundColor=[UIColor clearColor];
[button setTitleColor:[UIColor colorWithRed:0.3 green:0.1 blue:0.4 alpha:1.0] forState:UIControlStateNormal];
[self.view addSubview:btn];
现在边界:
[[button layer] setBorderWidth:2.0f];
[[button layer] setBorderColor:[UIColor greenColor].CGColor];
关于iphone - 带边框的透明按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14585749/