大佬教程收集整理的这篇文章主要介绍了iphone – UIButton作为UINavigationbar按钮,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
UIButton *refreshButton = [[UIButton alloc] init]; [refreshButton setImage:[UIImage imagenamed:@"refresh_icon.png"] forState:UIControlStateNormal]; [refreshButton addTarget:self action:@SELEctor(refreshSection) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithCustomView:refreshButton]; //[rightButton setImage:[UIImage imagenamed:@"refresh_icon.png"]]; << DOESN'T WORK EITHER self.navigationItem.rightBarButtonItem = rightButton; [refreshButton release]; [rightButton release];
UIImage *myImage = [UIImage imagenamed:@"myImage.png"]; UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithImage:myImage style:UIBarButtonItemStyleBordered target:self action:@SELEctor(refreshSection)]; self.navigationItem.rightBarButtonItem = button; [button release];
–
根据评论更新
在UIBarButtonItem中使用UIImageView作为自定义视图:
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imagenamed:@"myImage.png"]]; UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithCustomView:imageView]; self.navigationItem.rightBarButtonItem = rightButton; [imageView release]; [rightButton release];
–
更新
尝试了最后一种方法,虽然这看起来像你想要它,我似乎无法让它来处理水龙头.虽然目标和行动已经确定.
–
最后更新
我已经在问题中获得了您的初始代码&运行.图像未显示的原因是因为您尚未设置按钮的框架.设置框架后,图像将显示在导航栏中.
这是我使用过的片段&测试:
UIImage *myImage = [UIImage imagenamed:@"paw.png"]; UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom]; [myButton setImage:myImage forState:UIControlStateNormal]; myButton.showsTouchWhenHighlighted = YES; myButton.frame = CGRectMake(0.0,0.0,myImage.size.width,myImage.size.height); [myButton addTarget:self action:@SELEctor(tapped:) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithCustomView:myButton]; self.navigationItem.rightBarButtonItem = rightButton; [rightButton release]; [myButton release];
注意:我已经设置了UIButton的showsTouchWhenHighlighted属性,以便在按下按钮时可视地高亮显示该按钮.
以上是大佬教程为你收集整理的iphone – UIButton作为UINavigationbar按钮全部内容,希望文章能够帮你解决iphone – UIButton作为UINavigationbar按钮所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。