1

Facebook メッセージのような円形の UIView を作成するにはどうすればよいですか。

角が丸い長方形ですか、それとも中央に円形の画像がある長方形ですか?

画像ビュー は次ここに画像の説明を入力 のとおりです。カスタム セル クラスの initWithStyle コードは次のとおりです。

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code

        [self.userImage setBackgroundColor:[UIColor orangeColor]];
        [self.userImage.layer setCornerRadius:32.0f];
    }
    return self;
}

しかし、私はまだ長方形のイメージビューを取得しています。

4

3 に答える 3

6

ビューのレイヤーで cornerRadius プロパティを変更する必要があります。円を得るには、ビューの高さ/幅の半分に等しいコーナー半径を割り当てる必要があります。基本的な例を次に示します。

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100.0f, 100.0f, 120.0f, 120.0f)];
[view setBackgroundColor:[UIColor orangeColor]];
[view.layer setCornerRadius:60.0f];
[self.view addSubview:view];
于 2013-08-29T20:35:59.930 に答える
0

次のようにclipToBoundを使用してください:

[cell.yourImage.layer setBorderWidth:2.0f];
[cell.yourImage.layer setBorderColor:[[UIColor blackColor] CGColor]];
[cell.yourImage.layer setShadowRadius:5.0];
[cell.yourImage.layer setShadowOpacity:0.5];
[cell.yourImage.layer setShadowOffset:CGSizeMake(1.0, 0.0)];
[cell.yourImage.layer setShadowColor:[[UIColor blackColor] CGColor]];
[cell.yourImage.layer setCornerRadius:10.0];
cell.yourImage.clipsToBounds = YES;

それが役に立てば幸い

于 2014-01-29T14:57:35.357 に答える
0

「viewName」という名前のUIViewを使用していますが、UIImageで使用できます。

    //Define background color
    self.viewName setBackgroundColor:[UIColor colorWithRed:(84.0 / 255.0) green:(198.0 / 255.0) blue:(89.0 / 255.0) alpha:1]];

    //Create circular view
    self.viewName.layer.cornerRadius = cell.statusColor.frame.size.width / 2;
    self.viewName.clipsToBounds = YES;
于 2014-07-05T17:46:41.083 に答える