和I have this image.
(保存它,因为它与StackOverflow背景颜色相同,所以你无法在这里看到它)
如何将第一张图像中的边框添加到UIbarbuttonItem?有没有自己画画可能吗?
提前致谢.
解决方法 还有一个解决方案是创建UIbutton对象并使用它的图层属性.我做了一些基本设置,看起来像蓝色图像,如下所示:
在vIEwDIDLoad()方法中添加以下代码,还包括< QuartzCore / QuartzCore.h>框架.
UIbutton *button = [UIbutton buttonWithType:UIbuttonTypeCustom];[button setFrame:CGRectMake(0,50,40)];[button setimage:[UIImage imagenamed:@"settings.png"] forState:UIControlStatenormal];button.layer.borderWIDth = 1.0f;button.layer.bordercolor = [UIcolor lightGraycolor].CGcolor;button.layer.cornerRadius = 5.0f;button.layer.shadowcolor = [UIcolor lightGraycolor].CGcolor;button.layer.shadowRadius = 4.0f;button.layer.shadowOpacity = .9;button.layer.shadowOffset = CGSizeZero;button.layer.masksToBounds = NO;UIbarbuttonItem *leftItem = [[UIbarbuttonItem alloc] initWithCustomVIEw:button];self.navigationItem.leftbarbuttonItem = leftItem;
添加更多渐变效果
我确实找到了一个git帮助YIInnerShadowView看看,它非常有用.
我使用这些类来使渐变和阴影看起来像蓝色图像.能够与该图像有很多相似之处.您可以对这些类进行更多自定义以获得所需的准确性.
将此库添加到项目中,导入#import“YIInnerShadowVIEw.h”并将代码添加到vIEwDIDLoad()
YIInnerShadowVIEw *innerVIEw = [[YIInnerShadowVIEw alloc] initWithFrame:CGRectMake(0,40)];innerVIEw.shadowRadius = 1.5;innerVIEw.cornerRadius = 5;innerVIEw.shadowMask = YIInnerShadowMaskAll;innerVIEw.layer.bordercolor = [UIcolor colorWithRed:0.3843 green:0.6235 blue:0.8156 Alpha:1.0].CGcolor;innerVIEw.layer.borderWIDth = 1.0;UIbutton *button = [UIbutton buttonWithType:UIbuttonTypeCustom];[button setFrame:CGRectMake(0,40)];[button setimage:[UIImage imagenamed:@"settings.png"] forState:UIControlStatenormal];[innerVIEw addSubvIEw:button];UIbarbuttonItem *leftItem = [[UIbarbuttonItem alloc] initWithCustomVIEw:innerVIEw];self.navigationItem.leftbarbuttonItem = leftItem;
在YIInnerShadowLayer.m类中也做了一些修改:
- (ID)init{ self = [super init]; if (self) { self.masksToBounds = YES; self.needsdisplayOnBoundsChange = YES; self.shouldRasterize = YES; // Standard shadow stuff [self setShadowcolor:[[UIcolor colorWithWhite:0 Alpha:1] CGcolor]]; [self setShadowOffset:CGSizeMake(0.0f,1.0f)]; [self setShadowOpacity:1.0f]; [self setShadowRadius:5]; // Causes the inner region in this example to NOT be filled. [self setFillRule:kCAFillRuleEvenOdd]; self.shadowMask = YIInnerShadowMaskAll; } return self;}总结
以上是内存溢出为你收集整理的ios – 如何将边框添加到UIBarButtonItem全部内容,希望文章能够帮你解决ios – 如何将边框添加到UIBarButtonItem所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)