Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I worked this out with the help of Ashley.</p> <p>First of all i subclassed a UIView. Creating a own constructor for my Class called <code>- (id)initWithContentView:(UIView *)aView forTableView:(UITableView *)table andIndex:(NSIndexPath *)indexPath;</code>. In this constructor i determine what kind of table cell i am want to style.</p> <p>Then i overwrite l <code>- (void)layoutSubviews</code> to create the <code>CAShapeLayer</code> and applying the layer mask.</p> <p>.h File Code</p> <pre><code>typedef enum { tableCellMiddle, tableCellTop, tableCellBottom, tableCellSingle } tableCellPositionValue; @interface TableCellBackgrounds : UIView { tableCellPositionValue position; } - (id)initWithContentView:(UIView *)aView forTableView:(UITableView *)table andIndex:(NSIndexPath *)indexPath; @end </code></pre> <p>.m File Code</p> <pre><code>- (id)initWithContentView:(UIView *)aView forTableView:(UITableView *)table andIndex:(NSIndexPath *)indexPath { self = [super initWithFrame:aView.frame]; [self setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; if(self) { [self setBackgroundColor:[UIColor colorWithRed:(float)230/255 green:(float)80/255 blue:(float)70/255 alpha:1]]; if(table.style == UITableViewStyleGrouped) { int rows = [table numberOfRowsInSection:indexPath.section]; if(indexPath.row == 0 &amp;&amp; rows == 1) { self.layer.cornerRadius = 11; position = tableCellSingle; } else if (indexPath.row == 0) position = tableCellTop; else if (indexPath.row != rows - 1) position = tableCellMiddle; else position = tableCellBottom; } } return self; } - (void)layoutSubviews { [super layoutSubviews]; if(position == tableCellTop) { CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.path = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:(CGSize){10.0, 10.0}].CGPath; self.layer.mask = maskLayer; } else if (position == tableCellBottom) { CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.path = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight cornerRadii:(CGSize){10.0, 10.0}].CGPath; self.layer.mask = maskLayer; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload