0
我對Xcode很新,這個簡單的問題一直讓我生氣!我創建了一個可以正常工作的可擴展表格。這是一些在UIView子類,因爲當你在電池接頭展開的部分代碼:標題圖像在可擴展表格中不可調整
- (id)initWithFrame:(CGRect)frame WithTitle: (NSString *) title Section:(NSInteger)sectionNumber delegate: (id <SectionView>) Delegate
{
self = [super initWithFrame:frame];
if (self) {
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(discButtonPressed:)];
[self addGestureRecognizer:tapGesture];
self.userInteractionEnabled = YES;
self.section = sectionNumber;
self.delegate = Delegate;
CGRect LabelFrame = CGRectMake(100, 100, 100, 100);
LabelFrame.size.width -= 100;
CGRectInset(LabelFrame, 1.0, 1.0);
//BUTTON
CGRect buttonFrame = CGRectMake(LabelFrame.size.width, 0, 100, LabelFrame.size.height);
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = buttonFrame;
//[button setImage:[UIImage imageNamed:@"carat.png"] forState:UIControlStateNormal];
//[button setImage:[UIImage imageNamed:@"carat-open.png"] forState:UIControlStateSelected];
[button addTarget:self action:@selector(discButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:button];
self.discButton = button;
//My IMAGE
NSString *imageName = @"gradient1.png";
UIImage *myImage = [UIImage imageNamed:imageName];
UIImageView *sectionHeaderView = [[UIImageView alloc] initWithImage:myImage];
UIImageView *imageView = [[UIImageView alloc] initWithImage:myImage];
imageView.frame = CGRectMake(20,50,100,100);
[self addSubview:sectionHeaderView];
self.headerBG = sectionHeaderView;
//HEADER LABEL
UILabel *label = [[UILabel alloc] initWithFrame: CGRectMake(22, 12, sectionHeaderView.frame.size.width, 35.0)];
label.textAlignment = NSTextAlignmentLeft;
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor whiteColor];
label.shadowColor = [UIColor darkGrayColor];
label.shadowOffset = CGSizeMake(0.0, -1.0);
label.text = title;
label.font = [UIFont fontWithName:@"AvenirNext-Bold" size:20.0];
sectionHeaderView.backgroundColor = [UIColor clearColor];
//label.textAlignment = UITextAlignmentLeft;
[self addSubview:label];
self.sectionTitle = label;
}
return self;
}
我對細胞@「gradient1.png」自定義圖像,但我似乎並沒有做能夠調整它?這是在的UITableViewController頭部代碼:
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection: (NSInteger)section
{
SectionInfo *array = [self.sectionInfoArray objectAtIndex:section];
if (!array.sectionView)
{
NSString *title = array.category.name;
array.sectionView = [[SectionView alloc] initWithFrame:CGRectMake(0, 10, self.tableView.bounds.size.width, 0) WithTitle:title Section:section delegate:self];
}
return array.sectionView;
}
很抱歉,如果這是一個簡單的問題,你的幫助是非常感謝!
非常感謝你!我試圖調整不是在單元格中的imageView框架,非常愚蠢的 – luliger
你能否幫我解決另一個問題,再簡單一點。如何爲不同的頭文件創建不同的圖片? – luliger
你有你的數組,你正在填充你的tableview。只要基於該數組中的某個條件來做一個條件語句。說如果我的數據說什麼'UIImage * myImage = [UIImage imageNamed:@「someImage];',否則,如果我的數據說別的東西'UIImage * myImage = [UIImage imageNamed:@」somethingElse];' – Putz1103