iphone – 从UINavigationBar中的按钮中删除闪光效果

iphone – 从UINavigationBar中的按钮中删除闪光效果,第1张

概述如何从导航栏上的按钮删除光泽/光泽效果? 如果我通过使用自定义图像自定义导航栏,按钮不受影响,我可以从中删除效果(线条和光泽),还是为整个按钮定义十六进制颜色代码,甚至为其定义一个自定义图像? 我刚刚经历了这个过程.基本上,您需要创建自定义的可拉伸图像,并将其用作按钮的背景来摆脱光泽.更换UINavigationController中的后退按钮有点困难.为此,我使用UINavigationCon 如何从导航栏上的按钮中删除光泽/光泽效果?
如果我通过使用自定义图像自定义导航栏,按钮不受影响,我可以从中删除效果(线条和光泽),还是为整个按钮定义十六进制颜色代码,甚至为其定义一个自定义图像?解决方法 我刚刚经历了这个过程.基本上,您需要创建自定义的可拉伸图像,并将其用作按钮的背景来摆脱光泽.更换UINavigationController中的后退按钮有点困难.为此,我使用UINavigationControllerDelegate替换默认后退按钮与我的自定义按钮.

这里有一些代码:

>在UIbarbuttonItem上创建一个创建自定义按钮的类别.这是我的我使用这个类别来定制常规的按钮和后退按钮:

@interface UIbarbuttonItem (UIbarbuttonItem_customBackground)+ (ID) custombarbuttonWithTitle:(Nsstring *)Title target:(ID)target selector:(SEL)selector;+ (ID) customBackbuttonWithTitle:(Nsstring *)Title target:(ID)target selector:(SEL)selector;@end@implementation UIbarbuttonItem (UIbarbuttonItem_customBackground)+ (ID) custombuttonWithImagenamed:(Nsstring *)imagename selectedImagenamed:(Nsstring *)selectedImagename @R_419_6823@CapWIDth:(CGfloat)@R_419_6823@CapWIDth edgeInsets:(UIEdgeInsets)edgeInsets Title:(Nsstring *)Title target:(ID)target selector:(SEL)selector {    UIbutton* custombutton = [UIbutton buttonWithType:UIbuttonTypeCustom];    [custombutton addTarget:target action:selector forControlEvents:UIControlEventtouchUpInsIDe];    custombutton.TitleLabel.Font = [UIFont boldSystemFontOfSize:12.0f];    custombutton.TitleLabel.shadowcolor = [UIcolor colorWithRed:0.0f/255.0f green:0.0f/255.0f blue:0.0f/255.0f Alpha:0.25f];    custombutton.TitleLabel.shadowOffset = CGSizeMake(0.0f,-1.0f);    custombutton.TitleLabel.lineBreakMode = UIlineBreakModeTailTruncation;    custombutton.TitleEdgeInsets = edgeInsets;    UIImage* navbuttonBackgroundImage = [[UIImage imagenamed:imagename] stretchableImageWith@R_419_6823@CapWIDth:@R_419_6823@CapWIDth topCapHeight:0.0f];    UIImage* navbuttonpressedBackgroundImage = [[UIImage imagenamed:selectedImagename] stretchableImageWith@R_419_6823@CapWIDth:@R_419_6823@CapWIDth topCapHeight:0.0f];    [custombutton setBackgroundImage:navbuttonBackgroundImage forState:UIControlStatenormal];    [custombutton setTitle:Title forState:UIControlStatenormal];    [custombutton setBackgroundImage:navbuttonpressedBackgroundImage forState:UIControlStateHighlighted];    [custombutton setBackgroundImage:navbuttonpressedBackgroundImage forState:UIControlStateSelected];    CGSize size = CGSizeMake(30.0f,30.0f);    if (Title != nil) {        size = [[Nsstring stringWithString:Title] sizeWithFont:custombutton.TitleLabel.Font];    }    custombutton.frame = CGRectMake(0.0f,0.0f,size.wIDth + 20.0f,30.0f);    custombutton.layer.shouldRasterize = YES;    custombutton.layer.rasterizationScale = [[UIScreen mainScreen] scale];    return [[[UIbarbuttonItem alloc] initWithCustomVIEw:custombutton] autorelease];}+ (ID) custombarbuttonWithTitle:(Nsstring *)Title target:(ID)target selector:(SEL)selector {    return [self custombuttonWithImagenamed:@"navbuttonBG.png"                  selectedImagenamed:@"navbuttonpressedBG.png"                        @R_419_6823@CapWIDth:6.0f                          edgeInsets:UIEdgeInsetsMake(0.0f,5.0f,5.0f)                               Title:Title                              target:target                            selector:selector];}+ (ID) customBackbuttonWithTitle:(Nsstring *)Title target:(ID)target selector:(SEL)selector {        return [self custombuttonWithImagenamed:@"backbuttonBG.png"                  selectedImagenamed:@"backbuttonpressedBG.png"                        @R_419_6823@CapWIDth:12.0f                          edgeInsets:UIEdgeInsetsMake(0.0f,11.0f,5.0f)                               Title:Title                              target:target                            selector:selector];}@end

>将按钮添加到您的UINavigationbar

UIbarbuttonItem* logoutbutton = [UIbarbuttonItem custombarbuttonWithTitle:@"logout" target:self selector:@selector(logout)];self.navigationItem.rightbarbuttonItem = logoutbutton;

>如果还要替换UINavigationController的后退按钮,请设置一个UINavigationControllerDelegate并实现如下所示的willShowVIEwController方法:

- (voID)navigationController:(UINavigationController *)navigationController willShowVIEwController:(UIVIEwController *)vIEwController animated:(BOol)animated {    if([navigationController.vIEwControllers count ] > 1) {        UIVIEwController* backVIEwController = [navigationController.vIEwControllers objectAtIndex:(navigationController.vIEwControllers.count - 2)];        Nsstring* backText = backVIEwController.Title;        UIbarbuttonItem* newBackbutton = [UIbarbuttonItem customBackbuttonWithTitle:backText target:navigationController selector:@selector(popVIEwControllerAnimated:)];        vIEwController.navigationItem.@R_419_6823@barbuttonItem = newBackbutton;        vIEwController.navigationItem.hIDesBackbutton = YES;    }}

>以下是我使用的可伸缩图像:

>返回按钮:按下:>常规按钮:按下:

总结

以上是内存溢出为你收集整理的iphone – 从UINavigationBar中的按钮中删除闪光效果全部内容,希望文章能够帮你解决iphone – 从UINavigationBar中的按钮中删除闪光效果所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1057677.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存