【发布时间】:2016-06-14 22:37:04
【问题描述】:
嗨,我是 iOS 新手,在我的应用程序中我使用的是 TableList,我想将 tableList 单元格角半径设置为 3.0。这是我的代码。它仅在左角而不是所有角上应用圆角半径。
我的代码:-
- (CGFloat)tableView:(UITableView *)aTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 75;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = @"MyCell";
Cell = (MyTripsCell *)[MaintableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (Cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyTripsCell" owner:self options:nil];
Cell = [nib objectAtIndex:0];
}
Cell.layer.cornerRadius = 0.0;
Cell.selectionStyle = UITableViewCellSelectionStyleNone;
return Cell;
}
-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *) cell forRowAtIndexPath:(NSIndexPath *)indexPath{
cell.contentView.backgroundColor = [Bg colorWithHexString:@"EEEEEE"];
UIView * whiteRoundedView = [[UIView alloc]initWithFrame:CGRectMake(0, 12, MaintableView.frame.size.width, 70)];
whiteRoundedView.layer.backgroundColor = [Bg colorWithHexString:@"FDFDFD"].CGColor;
whiteRoundedView.layer.masksToBounds = YES;
whiteRoundedView.layer.cornerRadius = 3.0;
whiteRoundedView.layer.shadowOffset = CGSizeMake(-1, -1);
[cell.contentView addSubview:whiteRoundedView];
[cell.contentView sendSubviewToBack:whiteRoundedView];
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
[cell setPreservesSuperviewLayoutMargins:NO];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
【问题讨论】:
-
你在使用自动布局吗?
-
不,我没有使用自动布局
-
两个左角你得到半径了吗?顶部还是底部?
-
在 cellforrowat indexpath 中调用你的函数,它确实有效
-
我要设置圆角半径的所有边
标签: ios objective-c uitableview