我正在创建 UITableViewController 的单元格。其中一个包含一个小图像。我尝试了以下方法使其角变圆:
profileImage.layer.cornerRadius = 8;
profileImage.clipsToBounds = YES;
在另一个单元原型中,我尝试将按钮的角设为圆形:
chooseImageFromRoll.clipsToBounds = YES;
chooseImageFromRoll.layer.cornerRadius = 8;
在这两种情况下,我都包括
#import <QuartzCore/QuartzCore.h>
必须圆角的按钮和图像是拥有它们的 UITableViewController 的属性:
#import <UIKit/UIKit.h>
@interface profileRegistrationCellVC : UITableViewCell
@property (weak, nonatomic) IBOutlet UIImageView *profileImage;
@property (weak, nonatomic) IBOutlet UIButton *chooseImageFromRoll;
@property (weak, nonatomic) IBOutlet UIButton *shootImage;
@end
在相对 .m 类中:
#import "profileRegistrationCellVC.h"
#import <QuartzCore/QuartzCore.h>
@implementation profileRegistrationCellVC
@synthesize profileImage;
@synthesize chooseImageFromRoll;
@synthesize shootImage;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
chooseImageFromRoll.clipsToBounds = YES;
chooseImageFromRoll.layer.cornerRadius = 8;
shootImage.layer.cornerRadius = 8;
profileImage.layer.cornerRadius = 8;
profileImage.clipsToBounds = YES;
profileImage.layer.borderColor = [UIColor whiteColor].CGColor;
profileImage.layer.borderWidth = 20.0;
[self addSubview:profileImage];
[self addSubview:chooseImageFromRoll];
[self addSubview:shootImage];
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
这是我的 uitableviewcontroller 中的函数 cellForRowAtIndexPath 的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
static NSString *CellIdentifier = @"profileRegistrationCell";
profileRegistrationCellVC *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[profileRegistrationCellVC alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
//cell.profileImage.image.layer.masksToBounds = YES;
//cell.profileImage.layer.cornerRadius = 5.0;
return cell;
}
else if (indexPath.section == 1) {
static NSString *CellIdentifier = @"regularRegistrationCell";
regularRegistrationCellVC *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[regularRegistrationCellVC alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.regularFieldName.text = [_registrationItems objectAtIndex:indexPath.row];
if ([[_registrationItems objectAtIndex:indexPath.row] isEqualToString:@"Email*"])
cell.regularTextField.keyboardType = UIKeyboardTypeEmailAddress;
if ([[_registrationItems objectAtIndex:indexPath.row] isEqualToString:@"Età"]) {
cell.regularTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
}
return cell;
}
else{
static NSString *CellIdentifier = @"orientationRegistrationCell";
orientationRegistrationCellVC *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[orientationRegistrationCellVC alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.fieldLabel.text = [_registrationItems objectAtIndex:[_registrationItems count]-1];
cell.orientationLabel.text = @"Non specificato";
return cell;
}
}
但在任何情况下,我都没有设法使角落变圆。你能告诉我哪里错了吗?
谢谢