gpt4 book ai didi

iphone - 使用 cornerradius IOS 使其变圆时发出相关的 UIimageView

转载 作者:可可西里 更新时间:2023-11-01 06:24:56 24 4
gpt4 key购买 nike

我在 XIB 文件中获取了 UIView。在这个 View 中有一个 UIImageView 和相同大小的按钮。我想让那个 View 变圆,为此我正在使用 cornerRadius。 View 的大小是 92 * 92,这就是我使用 46 的 cornerRadius 使其变圆的原因。下面是我的代码,我正在评论我在代码本身中遇到的问题。

- (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];
}

最佳答案

试试这段代码:

_roundView.layer.cornerRadius = _roundView.frame.size.height / 2;
_roundView.layer.masksToBounds = YES;

绑定(bind)的面具是强制性的..此外,如果您使用公式而不是直接值,您的代码将变得更加灵活。希望对你有帮助!!祝你好运!!

关于iphone - 使用 cornerradius IOS 使其变圆时发出相关的 UIimageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17563173/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com