简体   繁体   English

如何使iOS FBSDKProfilePictureView回合?

[英]How to make iOS FBSDKProfilePictureView Round?

I'm trying to making a FBSDKProfilePictureView rounded but I can't. 我正在尝试使FBSDKProfilePictureView取整,但我不能。

This what I have: 这是我所拥有的:

ViewController.h ViewController.h

@property (weak, nonatomic) IBOutlet FBSDKProfilePictureView *fbPhoto;

ViewController.m on ViewDidLoad ViewDidLoad上的ViewController.m

self.fbPhoto.layer.cornerRadius = 30.0;
self.fbPhoto.layer.borderColor = [UIColor lightGrayColor].CGColor;
self.fbPhoto.layer.borderWidth = 1.0;

It makes a round circle in front of the UIIMage but it doesn't "crop" the image. 它在UIIMage前面制作了一个圆形圆圈,但没有“裁剪”图像。

How can i do it 我该怎么做

just set clipsToBounds 只需设置clipsToBounds

self.fbPhoto.layer.cornerRadius = 30.0;
self.fbPhoto.clipsToBounds=YES;
self.fbPhoto.layer.borderColor = [UIColor lightGrayColor].CGColor;
self.fbPhoto.layer.borderWidth = 1.0;

First of all for set rounded profile picture like whats up and FB, you can use below logic for that and after set setAutoresizesSubviews to NO of fbPhoto class. 首先,要设置舍入的个人资料图片(如whats up和FB),可以为此使用以下逻辑,并将setAutoresizesSubviews设置为fbPhoto类的NO之后。

use below code instead of your.. 使用以下代码代替您的代码。

[self.fbPhoto.layer setCornerRadius:self.fbPhoto.frame.size.height/2];
[self.fbPhoto.layer setBorderColor:[UIColor lightGrayColor].CGColor];
[self. fbPhoto.layer setBorderWidth:1];
[self.fbPhoto setAutoresizesSubviews:NO];

Jay's suggestion works. 周杰伦的建议行之有效。 Here it is in swift: 这是迅速的:

    //rounded corners
    ProfilePicture.layer.cornerRadius = ProfilePicture.frame.size.width / 2
    ProfilePicture.layer.borderColor = UIColor.whiteColor().CGColor
    ProfilePicture.layer.borderWidth = 1.0;
    ProfilePicture.clipsToBounds = true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM