// Create "back" UIbarbuttonItemUIbutton *backbutton = [UIbutton buttonWithType:UIbuttonTypeCustom];backbutton.frame = CGRectMake(0,28,17);[backbutton addTarget:self action:@selector(backbuttonTapped) forControlEvents:UIControlEventtouchUpInsIDe];backbutton.showstouchWhenHighlighted = YES;UIImage *backbuttonImage = [UIImage imagenamed:@"back-button.png"];[backbutton setBackgroundImage:backbuttonImage forState:UIControlStatenormal];UIbarbuttonItem *backbarbuttonItem = [[UIbarbuttonItem alloc] initWithCustomVIEw:backbutton];[toolbaritems addobject:backbarbuttonItem];
但是,水龙头的目标很小.更准确地说,它们是自定义图像的大小. (这又是微小的)有没有办法增加他们的目标的大小?
(注意:改变UIbuttons的frame属性只是拉伸图像.)
解决方法 您的代码的细微变化将会做到这一点需要更改:
>我假设backbuttonImage的大小是{28,17},并将按钮框设置为CGRectMake(0,48,37)
>删除backGroundImage并使用setimage:
>将属性imageEdgeInsets设置为UIEdgeInsetsMake(10,10,10)
你的代码将如下所示:
UIbutton *backbutton = [UIbutton buttonWithType:UIbuttonTypeCustom];backbutton.frame = CGRectMake(0,37);[backbutton addTarget:self action:@selector(backbuttonTapped) forControlEvents:UIControlEventtouchUpInsIDe];backbutton.showstouchWhenHighlighted = YES;UIImage *backbuttonImage = [UIImage imagenamed:@"back-button.png"];[backbutton setimage:backbuttonImage forState:UIControlStatenormal];backbutton.imageEdgeInsets = UIEdgeInsetsMake(10,10);UIbarbuttonItem *backbarbuttonItem = [[UIbarbuttonItem alloc] initWithCustomVIEw:backbutton];[toolbaritems addobject:backbarbuttonItem];
您可以根据您的要求更改框架和imageEdgeInsets的值.这段代码为我工作.
总结以上是内存溢出为你收集整理的ios – 自定义UIBarButtonItems从UIButtons与自定义图像 – 是否可以使点击目标更大?全部内容,希望文章能够帮你解决ios – 自定义UIBarButtonItems从UIButtons与自定义图像 – 是否可以使点击目标更大?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)