UIImage 围成一圈

UIImage in a circle(UIImage 围成一圈)

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

问题描述

有人可以帮我吗?新作为 iPhone 开发人员.我正在尝试以圆形而不是 iPhone 标准的矩形显示 .png 图片

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 文件都是矩形",但如果你想在屏幕上显示圆形或其他非矩形对象,你可以通过使用透明度.为了确保图像中的透明像素在 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];

如果你只是想添加圆角,做一个圆,如果你已经将 QuartzCore 框架添加到你的项目中,你也可以像这样使用cornerRadius 属性:

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 围成一圈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:UIImage 围成一圈

基础教程推荐