7

次のコードを使用してみましたが、うまくいきませんでした。iOS 6でこれを行う方法を知っている人はいますか? カスタムセルを作成したくありません。

self.tableView.layer.cornerRadius = 5.0f;
    [self.tableView setClipsToBounds:YES];

編集:

実際に起こっていることは、このコードが個々の UITableViewSection ではなく、ビュー全体のコーナー半径を作成しているようです。これは理にかなっていますか?

私も試してみ[cell.layer setCornerRadius:3.0];ましたが、運もありませんでした。私の UITableView のコーナーはまだまったく同じです。

ここに画像の説明を入力

4

10 に答える 10

19

TableViewCell の backgroundView を変更し、UIView のサブクラスを作成し、レイヤー クラスを変更できます。

@interface BackgroundView : UIView
@end

@implementation BackgroundView

+ (Class)layerClass
{
    return [CAShapeLayer class];
}
@end

後で cellForRowAtIndexPath で次のようにします。

static NSString *CellIdentifier = @"CustomCell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

CGRect frame = cell.backgroundView.frame;
cell.backgroundView = [[BackgroundView alloc] initWithFrame:frame];

CGFloat corner = 20.0f;
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:cell.backgroundView.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(corner, corner)];
CAShapeLayer  *shapeLayer = (CAShapeLayer *)cell.backgroundView.layer;
shapeLayer.path = path.CGPath;
shapeLayer.fillColor = cell.textLabel.backgroundColor.CGColor;
shapeLayer.strokeColor = [UIColor lightGrayColor].CGColor;
shapeLayer.lineWidth = 1.0f;

return cell;

結果は次のとおりです。

ここに画像の説明を入力

必要なコーナーを変更したり、別のパスを作成したりできます。

お役に立てば幸いです。

于 2013-08-14T19:20:16.363 に答える
3

セルの角の半径を設定する代わりに、cell.contentview の半径を次のように設定します。

cell.contentView.layer.cornerRadius = 10.0f;
cell.contentView.layer.borderColor = [UIColor blackColor].CGColor;
cell.contentView.layer.borderWidth = 3.0f;

セルの初期化中に上記のコードを配置します。

于 2014-02-03T12:59:35.453 に答える
3

これを .h ファイルに追加します

#import <QuartzCore/QuartzCore.h>

そして、あなたのコードで以下を使用してください、

tblView.layer.cornerRadius=5.0f;
于 2013-08-17T04:34:41.973 に答える
2

これでできます。それは私のために働いています

    UILabel *delLbl = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 300, 44)];
    delLbl.font = [UIFont fontWithName:@"Arial-BoldMT" size:18];
    delLbl.layer.cornerRadius = 10.0f;
    delLbl.layer.borderWidth = 1.0f;
    delLbl.layer.borderColor = [UIColor grayColor].CGColor;
    delLbl.text = @"Cell Text";
    delLbl.textAlignment = NSTextAlignmentCenter;
    [cell.contentView addSubview:delLbl];
    cell.backgroundView = [[UIView alloc] initWithFrame:CGRectZero];
    Return Cell;
于 2013-08-07T05:43:15.337 に答える
2

プロジェクトに Quartzcore フレームワークを追加する

import QuartzCore/QuartzCore.h to your .h file

self.tableView.layer.cornerRadius = 5.0f;

于 2013-08-07T05:29:50.357 に答える
2

このコード行が欠落していると思います:

[self.tableView.layer setMasksToBounds:YES];
于 2013-08-07T05:38:52.677 に答える
2

最初に、QuartzCode フレームワークを使用する必要があります。そのフレームワークをインポートし、.h ファイルを宣言します。レイヤー効果を設定するクラスを指定します。

そして、そのメソッドを追加します

myTableView.layer.cornerRadius=5;
[myTableView setClipsToBounds:YES];

そして、コーナーラジオをセルに設定したい場合は、このコードも試しました

UITableViewCell.layer は CALayer クラスの一種で、CALayer クラスには cornerRadius というプロパティがあります。したがって、セルの角の半径を次のように設定します。

[cell.layer setCornerRadius:3.0];

このコードを試してください。

于 2013-08-07T05:41:31.653 に答える
1

これを試して:-

tableView.layer.cornerRadius=5.0f;
于 2013-08-07T06:03:50.477 に答える