使用cornerradius IOS使其圆形时发出相关的UIimageView
Posted
技术标签:
【中文标题】使用cornerradius IOS使其圆形时发出相关的UIimageView【英文标题】:issue related UIimageView while making it round using cornerradius IOS 【发布时间】:2013-07-10 05:41:01 【问题描述】:我在 XIB 文件中使用了 UIView。在这个视图中有一个 UIImageView 和一个相同大小的按钮。我想让那个视图变圆,为此我使用cornerRadius。视图的大小是 92 * 92,这就是为什么我要使用 46 的角半径来使其变圆的原因。下面是我的代码,我正在评论我在代码本身中遇到的问题。
- (void)viewDidLoad
[super viewDidLoad];
_roundView.layer.cornerRadius = 46;
flag=0;
selectImage.layer.cornerRadius = 46;
NSLog(@"%f",_roundView.frame.size.height);
NSLog(@"%f",_roundView.frame.size.width);
imageFrame = selectImage.frame;
// when first view appear its perfectly round
// this is how i pick image from gallery
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info
self.lastChosenMediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([lastChosenMediaType isEqual:(NSString *)kUTTypeImage])
UIImage *chosenImage = [info objectForKey:UIImagePickerControllerEditedImage];
UIImage *shrunkenImage = shrinkImage(chosenImage, imageFrame.size);
self.imagee = shrunkenImage;
NSLog(@"%f",_roundView.frame.size.height); nslog = 92
NSLog(@"%f",_roundView.frame.size.width); nslog = 92
NSLog(@"%f",_roundView.layer.cornerRadius); nslog = 46
NSLog(@"%f",selectImage.frame.size.height); nslog = 92
NSLog(@"%f",selectImage.frame.size.width); nslog = 92
NSLog(@"%f",selectImage.layer.cornerRadius); nslog = 46
selectImage.image = imagee;
selectImage.layer.cornerRadius = 46;
// now the issue is Image gets selected but it become rectangular 92 * 92
[picker dismissModalViewControllerAnimated:YES];
【问题讨论】:
【参考方案1】:试试这个代码:
_roundView.layer.cornerRadius = _roundView.frame.size.height / 2;
_roundView.layer.masksToBounds = YES;
绑定的面具是强制性的.. 此外,如果您使用公式而不是直接值,您的代码会变得更加灵活。 希望对你有帮助!!祝你好运!!
【讨论】:
【参考方案2】:试试下面的代码
roundView.layer.cornerRadius = 46;
_roundView.layer.masksToBounds = YES;
flag=0;
selectImage.layer.cornerRadius = 46;
selectImage.layer.masksToBounds = YES;
imageFrame = selectImage.frame;
【讨论】:
【参考方案3】:尝试使用这个..
_roundView.layer.masksToBounds = YES;
【讨论】:
以上是关于使用cornerradius IOS使其圆形时发出相关的UIimageView的主要内容,如果未能解决你的问题,请参考以下文章
较小尺寸的按钮不是带有 layer.cornerRadius 的圆形