- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
所以我创建了一个按钮。我希望它有圆角而不制作圆形的 .png 文件我可以设置背景图片。我可以绕过角落。但是,当我设置背景图像时,圆角消失了。
很久以前我做过一次,但似乎无法让它再次工作。如何做到这一点?
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
[button1 addTarget:self action:@selector(goSpecials)
forControlEvents:UIControlEventTouchUpInside];
[button1 setTitle:@"Specials" forState:UIControlStateNormal];
button1.titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:(15.0)];
[button1 setTitleColor:[self colorWithHexString:buttonColor] forState:UIControlStateNormal];
button1.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"button.png"]];
//[button1 setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal];
button1.frame = CGRectMake(20.0, 232.0, 135.0, 32.0);
button1.layer.borderColor = [UIColor blackColor].CGColor;
button1.layer.borderWidth = 0.5f;
button1.layer.cornerRadius = 8.0f;
[self.view addSubview:button1];
按钮.png:
最佳答案
将 maskToBounds 属性添加到您的按钮。
button1.layer.masksToBounds = YES;
关于iphone - 使用方形 setBackgroundImage 的圆角 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10554667/
我正在尝试关注 the Fabric.js tutorial到 setBackgroundImage 到我与按钮相关联的几个图像之一,并且变得有些奇怪。基本上,按钮 1 和 3 都很慢/没有响应/需要
导航栏和上面显示的分段控件之间有一条细黑线。我需要尝试删除此行。 导航栏不是半透明的(我不希望这样)。 我已经尝试过此代码,但无法正常工作: @IBOutlet var navBar: UINavig
我正在尝试自定义选项卡栏,并使用以下代码来更改背景。 UIImage *TabBarControllerBackground = [UIImage imageNamed:@"ios7TabBarBac
通常我可以设置 UITableView 的背景图片使用 [self.tableView setBackgroundView:imageView]; 此外,使用 SDWebImage 我可以分两步将图
我在iOS8中通过KVO设置了自定义navigationBar,自定义navigationBar设置了BackgroundImage。 我发现 viewContoller.view.frame.ori
我是 iOS 编程的新手,我正在创建我的第一个应用程序。我一直在尝试使用以下代码来更改导航栏背景图像(这是使用新的 iOS 5 方法): [self.navigationController.navi
我正在使用以下代码: UIImage *buttonImage; if (p.placeImage != nil) { buttonImage = [UIImage imageWithData
- (void)viewDidLoad { [super viewDidLoad]; [self.navigationController.navigationBar setBackgro
我有两个疑问: https://jsfiddle.net/2h5nbrr2/1/ 1。如何在背景图像中插入属性: function backchange(img) { var imag = img
UIImage *gradientImage46 = [[UIImage imageNamed:@"navbar.png"]resizableImageWithCapInsets:UIEdgeInse
像许多开发人员一样,我正在研究 IOS 5 的新功能。 我尝试使用外观代理来自定义我的应用程序。但是在某些方法中我得到了一个错误。 这个有效: [[UINavigationBar appearance
我正在尝试在 UIButton 上的文本顶部获取图像。我已将图像作为背景图像放在 UIButton 上并设置 VerticalAlignment,图像现在位于文本上方 :)像这样: button.im
我们使用 Storyboard添加了 UIBarButtonItem 并且在运行时点击我们想要更改它的图像(功能类似于添加书签/删除书签)。 研究堆栈溢出。很多人建议在 UIBarbuttonItem
我在 UIControlStateNormal 中的所有按钮下面都有一条小黑线。后退按钮和完成按钮不受影响。 这是图片: 看得一清二楚, super 讨厌。以下是我设置所有图像的方式: [[UIBar
所以我创建了一个按钮。我希望它有圆角而不制作圆形的 .png 文件我可以设置背景图片。我可以绕过角落。但是,当我设置背景图像时,圆角消失了。 很久以前我做过一次,但似乎无法让它再次工作。如何做到这一点
我正在尝试使用可调整大小的图像作为按钮背景。 UIImage *image = [UIImage imageNamed:@"btn_prev_secondary"]; UIEdgeInsets edg
我在 Xcode 4.2 Build 4D199 中创建了一个新的测试 iOS5 项目,并尝试如上所述设置 UINavigationBar 的外观,但没有任何反应。 我在viewDidLoad中试过的
当按下某个 Controller 时,我正在更改导航栏的背景图像。我想为这种变化制作动画。我可以使用以下代码这样做: [UIView transitionWithView:self.navigatio
我刚刚切换到 iOS 5,除了自定义导航栏外,我的应用程序中的一切似乎都正常工作。我环顾四周,听从了每个人关于调用新方法 setBackgroundImage: forBarMetrics: 的建议,
我正在尝试为 UIButton 设置图像。 我不知道 setBackgroundImage:Forstate 和 setImage:Forstate 之间的区别: 谁能帮帮我? 谢谢并致以最诚挚的问候
我是一名优秀的程序员,十分优秀!