2016-12-26 1 views
0

UITableViewで丸みを帯びたコーナーを達成しようとしています。私は私のMyUtils.mに存在するコードスニペット、以下で使用UITableView - ボトムラウンドコーナー

-

/* 
* To get rounded corners of view. 
*/ 
+ (UIView *)roundCornersOnView:(UIView *)view rectCorner:(UIRectCorner)corner radius:(float)radius 
{ 
    UIView *roundedView = view; 
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:roundedView.bounds byRoundingCorners:corner cornerRadii:CGSizeMake(radius, radius)]; 
    CAShapeLayer *maskLayer = [CAShapeLayer layer]; 
    maskLayer.frame = roundedView.bounds; 
    maskLayer.path = maskPath.CGPath; 
    roundedView.layer.mask = maskLayer; 
    return roundedView; 
} 

は、それから私は、2つのビューの角を丸めるために私の迅速ファイルからMyUtils法上と呼ばれます。 1つはUIViewで、もう1つはUITableViewです。 UIView

override func viewDidLayoutSubviews() { 
    super.viewDidLayoutSubviews() 
     MyUtils.roundCornersOnView(myUIView, rectCorner: [.TopLeft, .TopRight], radius: 15) 
     MyUtils.roundCornersOnView(myTableView, rectCorner: [.BottomLeft, .BottomRight], radius: 15) 
} 

ない問題、UITableViewの場合、私は私が達成したいが、その後UITableView開始は、その内容をスクロールしない下部の下丸みを帯びた角を見ることができます。

通常はUITableViewの内容がスクロールしますが、適用後にはUITableViewがスクロールを開始し、UITableViewがスクロールしている可能性があります。

+0

あなたmyTableViewにclipToBoundsを適用myTableViewの範囲を超えるコンテンツは表示されません。 – nferocious76

+0

@ nferocious76それを見ていただきありがとうございますが、不確かなことにうまくいきませんでした – Rahul

+0

は、その部分のスクリーンショットを私に見せることができましたか? – nferocious76

答えて

0

のtableViewの変更のそのtableViewWrapperプロパティのマスク層をオーバーライドし、私たちはコンテナビューを追加し、私たちのマスキングを実装する必要があり、これを解決するためにそれはとても奇妙な振る舞いが導入されています

@interface ViewController()<UITableViewDelegate, UITableViewDataSource> 

@property (weak, nonatomic) IBOutlet UIView *container; 
@property (weak, nonatomic) IBOutlet UITableView *testTable; 

@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

    CAShapeLayer * maskLayer = [CAShapeLayer layer]; 
    // manually configuring the mask rect will be the best way to set it rather than setting it in viewDidLayoutSubviews or viewDidAppear that can be called again when view is dismissed or popback. 
    CGRect rect = CGRectMake(0, 40, [UIScreen mainScreen].bounds.size.width - 40, [UIScreen mainScreen].bounds.size.height - 204); 

    maskLayer.path = [UIBezierPath bezierPathWithRoundedRect: rect byRoundingCorners: UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii: (CGSize){10.0, 10.}].CGPath; 

    self.container.layer.mask = maskLayer; 
    self.container.clipsToBounds = YES; 

} 


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

    return 15; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; 

    cell.textLabel.text = [NSString stringWithFormat:@"%ld", (long)indexPath.row]; 

    return cell; 
} 

@end 
+0

UIViewをテーブルのbackgroundViewとして設定できます。新しい親ビューを導入せずにそのbackgroundViewを更新できませんか? – Rahul

+0

番号backgroundVewの変更は、スクロールするたびにオフセットされますが、手動でサイズを変更することもできますが、tableViewの内容の背後にありますので、コーナーが無くなり無駄になります。 – nferocious76