189 8069 5689

iOSUIImage/UIImageView处理-创新互联

今天处理了把iOS6版本改为iOS7的过程了,遇到了一些问题,查了一些资料,纪录一下:

成都创新互联公司坚持“要么做到,要么别承诺”的工作理念,服务领域包括:网站建设、成都网站设计、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的长子网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

   1,iPad1上,更新图标以后最后先把原有程序卸载了,要不然图片残留很严重,还遇到一个问题说是调试过程中有其他进程在调试,重启iPad1就好了。就因为图片残留的问题,至少耽搁我1-2小时。

   2,UINavigationBar自定义:看看支持到4.3的解法:

#pragma mark -
#pragma mark 自定义导航栏背景
@implementation UINavigationBar (CustomImage)
- (UIImage *)barBackground
{
    UIImage *bg = [UIImage p_w_picpathNamed:@"bg_navbar_ios7.png"];
    if ([FMUSystem getOSVersion] < 7.0) {
        bg = [FMUImage p_w_picpathByScalingAndCroppingForSize:CGSizeMake(320, 44) SourceImage:bg CropType:FMUIMAGE_SCALE_TYPE_FITMIN];
//        UIGraphicsBeginImageContext(CGSizeMake(320,44));
//        CGContextRef context = UIGraphicsGetCurrentContext();
//        [bg drawInRect: CGRectMake(0, 0, 320,44)];
//        bg = UIGraphicsGetImageFromCurrentImageContext();
//        UIGraphicsEndImageContext();
    }
                                                                                                                                                                                                         
    return bg;
}
- (void)didMoveToSuperview
{
    //iOS5 only
    if ([self respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])
    {
        [self setBackgroundImage:[self barBackground] forBarMetrics:UIBarMetricsDefault];
    }
}
//this doesn't work on iOS5 but is needed for iOS4 and earlier
- (void)drawRect:(CGRect)rect
{
    //draw p_w_picpath
    [[self barBackground] drawInRect:rect];
}
@end

    为了支持iOS7,使用320*64的图片,还得我自己来裁一下。我个人比较喜欢注释掉的方法。上面的函数是其他同事实现的公有方法。

    3,生成圆形图

    3.1 layer层画圆角

UIImageView * p_w_picpathView = [[UIImageView alloc] initWithImage:[UIImage p_w_picpathNamed:@"oiuyfdsa.png"]];
p_w_picpathView.frame = CGRectMake(20.f, 20.f, 100.f, 100.f);
p_w_picpathView.layer.masksToBounds = YES;
p_w_picpathView.layer.cornerRadius = 50;

    3.2 画布画

-(UIImage*) circleImage:(UIImage*) p_w_picpath withParam:(CGFloat) inset {
    UIGraphicsBeginImageContext(p_w_picpath.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(context, 2);
    CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
    CGRect rect = CGRectMake(inset, inset, p_w_picpath.size.width - inset * 2.0f, p_w_picpath.size.height - inset * 2.0f);
    CGContextAddEllipseInRect(context, rect);
    CGContextClip(context);
                                                                                                                                                    
    [p_w_picpath drawInRect:rect];
    CGContextAddEllipseInRect(context, rect);
    CGContextStrokePath(context);
    UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newimg;
}

    4,图片平铺的方式

    4.1 图片转换为uicolor,设为背景,有点像OpenGL中纹理设置。

UIColor *circleColorPattern = [UIColor colorWithPatternImage:
[UIImage p_w_picpathNamed:@"circle_pattern.png"]];

    4.2 图片转换为类似android中9.png的方式

    iOS5之后:

UIImage *buttonBackgroundImage = [[UIImage p_w_picpathNamed:@"button_bkg.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,13,0,13)];
[button setBackgroundImage:buttonBackgroundImage forState:UIControlStateNormal];

    这是取27个像素,中间那个像素拉伸活者压缩。

    iOS5之前的方法:

- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth
topCapHeight:(NSInteger)topCapHeight;

  这个方法有局限性,它只能指定leftCapWidth和topCapHeight,然后只有一个像素能够重复,也就是rightCapWidth为 p_w_picpathWidth-leftCapWidth-1,而bottomCapHeight为 p_w_picpathHeight - topCapHeight -1,所以重复的始终是中间的那一个像素.

  最后摘录一份iOS6,7的适配文章,这文章已经看过2遍以上,可是需要的时候还要查,所以放在这里。

Like many of you, I have been very busy upgrading my apps to make them fit for iOS 7. The latest version of iOS introduces lots of visual changes. From a developer’s perspective, the navigation bar and status bar are two noticeable changes that need to cater. The status bar is now transparent, that means the navigation bar behind it shows through. In some cases, the background p_w_picpath for a navigation bar can extend up behind the status bar.

Some time ago, I’ve written a tutorial about how to customize a navigation bar. I think it’s time to revisit the customization and see how it is done in iOS 7. Here are some of the tips and tricks that you’ll find in this article:

  • Setting the background color of navigation bar

  • Using background p_w_picpath in navigation bar

  • Customizing the color of back button

  • Changing the font of navigation bar title

  • Adding multiple bar button items

  • Changing the style of status bar

  • Hiding the status bar

iOS UIImage/UIImageView处理

You’ll need Xcode 5 to properly execute the code as presented in this tutorial. So if you’re still using older versions of Xcode, make sure you upgrade to Xcode 5 before running the sample Xcode project.

Default Navigation Bar in iOS 7

Before we go in to the customization, let’s first take a look at the default navigation bar generated by Xcode 5 and iOS 7. Simply create a Xcode project using Single View Controller template. Embed the view controller in a navigation controller. If you don’t want to start from scratch, you can justdownload this sample Xcode project.

Xcode 5 bundles both iOS 6 and iOS 7 Simulators. Try to run the sample project using both versions of Simulators.

iOS UIImage/UIImageView处理

As you can see, the navigation bar in iOS 7 is by default intertwined with the status bar. The default color is also changed to light gray, as well.

Changing the Background Color of Navigation Bar

In iOS 7, the tintColor property is no longer used for setting the color of the bar. Instead, use the barTintColor property to change the background color. You can insert the below code in the didFinishLaunchingWithOptions: of AppDelegate.m.

1

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网页名称:iOSUIImage/UIImageView处理-创新互联
URL标题:http://cdxtjz.cn/article/cshdjc.html

联系我们

您好HELLO!
感谢您来到成都网站建设公司,若您有合作意向,请您为我们留言或使用以下方式联系我们, 我们将尽快给你回复,并为您提供真诚的设计服务,谢谢。
  • 电话:028- 86922220 18980695689
  • 商务合作邮箱:631063699@qq.com
  • 合作QQ: 532337155
  • 成都网站设计地址:成都市青羊区锣锅巷31号五金站写字楼6楼

小谭建站工作室

成都小谭网站建设公司拥有多年以上互联网从业经验的团队,始终保持务实的风格,以"帮助客户成功"为已任,专注于提供对客户有价值的服务。 我们已为众企业及上市公司提供专业的网站建设服务。我们不只是一家网站建设的网络公司;我们对营销、技术、管理都有自己独特见解,小谭建站采取“创意+综合+营销”一体化的方式为您提供更专业的服务!

小谭观点

相对传统的成都网站建设公司而言,小谭是互联网中的网站品牌策划,我们精于企业品牌与互联网相结合的整体战略服务。
我们始终认为,网站必须注入企业基因,真正使网站成为企业vi的一部分,让整个网站品牌策划体系变的深入而持久。