首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何以编程方式创建ole的OBShapedButton

如何以编程方式创建ole的OBShapedButton
EN

Stack Overflow用户
提问于 2012-02-23 14:36:28
回答 1查看 633关注 0票数 0

在项目中我必须创建一些非常规的buttons.on网络,我发现ole的OBShapedButton .It是很好的项目,所有的工作都是从xib.I完成的。我必须以编程的方式创建它.But它不工作。

1.将OBShapedButton.h、OBShapedButton.m、UIImage+ColorAtPixel.h和UIImage+ColorAtPixel.m添加到Xcode项目中。2.在视图控制器中创建OBShapedButton对象。

代码语言:javascript
复制
 obj_OBShapedButton=[[OBShapedButton alloc]init];
 obj_OBShapedButton = [UIButton buttonWithType:UIButtonTypeCustom];
 [obj_OBShapedButton setFrame:CGRectMake(10, 10, 160,161)];

[obj_OBShapedButton setImage:[UIImage imageNamed:@"button-normal.png"] forState:UIControlStateNormal];
[obj_OBShapedButton addTarget:self action:@selector(Buton_action) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:obj_OBShapedButton];

它会显示一个不规则形状的按钮。

这里的问题是整个按钮框架需要点击,而不是只接受图像…上的点击.does任何人尝试以编程方式执行ole的OBShapedButton ..

请让我知道。谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-02-23 15:27:36

首先创建一个OBShapedButton实例,然后用UIButton实例替换它。删除obj_OBShapedButton = [UIButton buttonWithType:UIButtonTypeCustom],因为您已经有一个分配给obj_OBShapedButton的对象

代码将如下所示:

代码语言:javascript
复制
obj_OBShapedButton = [OBShapedButton buttonWithType:UIButtonTypeCustom];
[obj_OBShapedButton setFrame:CGRectMake(10, 10, 160,161)];

[obj_OBShapedButton setImage:[UIImage imageNamed:@"button-normal.png"] forState:UIControlStateNormal];
[obj_OBShapedButton addTarget:self action:@selector(Buton_action) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:obj_OBShapedButton];
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9408278

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档