ついに全人類の悲願であったGrouped UITableViewCellのCorner Radiusが変更可能となる
えー、全人類の悲願ってことは絶対ないと思いますが、全俺の悲願ということでw
iPhoneアプリを開発し始めた時からGroupedなUITableViewのCorner Radiusの値を変えれないかなーと思っておりまして色々試してみたのですが、そのものずばりな方法がありませんでしたので作ってみました。
使い方
githubからリポジトリをcloneし、Classesフォルダにあるファイルをすべて自分のプロジェクトにインポートしてください。
インポートしたら、Corner Radiusを変更したいUITableViewDataSourceを実装しているクラスのcellForRowAtIndexPath:メソッド等で、UITableViewCellを実体化した後にUITableViewのconfigureCornerRadiusCell:メソッドを呼び出してください。この呼び出しを行った後からCorner RadiusとSeparator Heightが変更可能になります。
以下はリポジトリに入ってるExampleプロジェクトのコードの一部ですが、だいたい2〜3行追加するだけです。
#import "UITableView+TCRCornerRadiusAdditions.h" - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *identifier = @"CellIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; } // configureCornerRadiusCell methods add some functions to control corner radius [tableView configureCornerRadiusCell:cell]; // Modify additional properties cell.cornerRadius = 3.0f; cell.separatorHeight = 1.0f; cell.selectionStyle = UITableViewCellSelectionStyleBlue; cell.textLabel.text = [NSString stringWithFormat:@"section=%d row=%d", indexPath.section, indexPath.row]; return cell; }
TCRRoundRectCellBackgroundViewクラスのUIAppearanceを変更することでCorner Radiusのデフォルト値を変更することもできますが、あまりテストしてないので不具合があったらご連絡ください。