UIImage在一个圆圈 [英] UIImage in a circle

查看:129
本文介绍了UIImage在一个圆圈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我吗?新的iPhone开发人员。我试图在一个圆圈中显示一个.png图片而不是一个矩形,这是iPhone的标准

Can somebody help me here?. New as iPhone Developer. I am trying to display a .png picture in a circle instead of a rectangle which is the standard for iPhone

推荐答案

嗯,所有png文件是'矩形'但是如果你想在屏幕上显示圆圈或其他非矩形对象,你可以使用transparacy。要确保图像中的透明像素在iPhone上也是透明的,您可以设置要清除的UIImageView的背景颜色。这可以在Interface Builder中完成,方法是将背景颜色选择器中的不透明度滑块一直向下拖动,
或代码如下:

Well, all png files are 'rectangles' but if you want to have the apperence of a circle or other non rectangle object on the screen you can do so by using transparacy. To make sure the transparent pixels in the image are also transparent on the iPhone, you can set the background color of the UIImageView to clear. This can be done in Interface Builder by dragging the opacity slider in the background color picker all the way down, or in code as follows:

UIImage *image = [UIImage imageNamed:@"yourRoundImage.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.backgroundColor = [UIColor clearColor];
[self.view addSubview: imageView];

如果你只想添加圆角,做圆圈,你也可以使用cornerRadius属性如果您已将QuartzCore框架添加到项目中,请执行以下操作:

If you simply want to add rounder corners, to make a circle, you can also use the cornerRadius Property like this if you have added the QuartzCore framework to your project:

#import <QuartzCore/QuartzCore.h>
UIImage *image = [UIImage imageNamed:@"yourRoundImage.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.layer.cornerRadius = image.size.width / 2;
imageView.layer.masksToBounds = YES;
[self.view addSubview: imageView];

这篇关于UIImage在一个圆圈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆