我正在創建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
這裏是我的函數的cellForRowAtIndexPath的代碼,在我的UITableViewController:
- (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;
}
}
但在任何情況下,我設法讓圓角。你能說出我錯在哪裏嗎?
謝謝
請檢查編輯答案。 –
我提供的代碼首先用於創建一個按鈕,第二個用於圓角uiimage的角落。通過使用兩個蒙版並定義圓角半徑,如果您在訪問您的自定義單元格的cellfprrowatindexpath方法中使用它,它應該可以工作。在返回單元格之前,只需在方法內添加蒙版或半徑方法即可。也請張貼您的cellviewrow索引路徑的tableview,所以我可以看到你做了什麼。 –
我編輯我的帖子以添加cellForRowAtIndexPath代碼。 我忘了指定從故事板創建的按鈕和圖像。後者已經有背景顏色和標題,但我通過故事板界面指定它們是自定義按鈕。這一切都會影響我的代碼嗎?我的代碼變得無效了嗎?此外感謝 – ubisum