很多时候,会发现写UI也是很麻烦的一件事儿,比如你写一个tableview,不分页的,多余出来的底部非cell部分可能会出现分割线,可以设置为footerView,用 setTableViewFootView
//zhangqing 去除底部分割线
- (void)setExtraCellLineHidden: (UITableView *)tableView{
UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 350, SCREEN_WIDTH, SCREEN_HEIGHT-350-44)];
view.backgroundColor=KVIEW_Background_Color;
[tableView setTableFooterView:view];
[view release];
}
在有section的时候,滑动时官方默认的是section的view不会向上推出屏幕,而是保留在顶部,这样影响体验,可以把第一个section设置为headerView或者自己加一个headerView,然后第0个section的高度设置为0
//zhangqing 只有iphone才有
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
if (section==0) {
return 0;
}else if(section==1){
return 35;
}else return 0;
}
//zhangqing 只有iphone才有
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
if (section==0) {
CGRect headerFrame = {{0,0},{320,0}};
UIView *header = [[[UIView alloc] initWithFrame:headerFrame] autorelease];
return header;
}else{
UIView *searchHistoryHeaderView=[[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 35)]autorelease];
UILabel *searchHistoryText=[[UILabel alloc]initWithFrame:CGRectMake(13, 0, 70, 35)];
[searchHistoryText setText:@"历史记录:"];
searchHistoryText.font=[UIFont systemFontOfSize:15];
UIButton *clearnAllBtn = CreateButton(self, @"", @"clearnAllTapped:");
[clearnAllBtn.titleLabel setFont:KDJFont(15.0f)];
clearnAllBtn.titleLabel.textAlignment=NSTextAlignmentCenter;
clearnAllBtn.frameWidth=45;
clearnAllBtn.frameHeight=23;
clearnAllBtn.frameY=6;
clearnAllBtn.frameX=SCREEN_WIDTH-45;
[clearnAllBtn setImage:PNG_FROM_NAME(@"delAllHistory.png") forState:UIControlStateNormal];
[clearnAllBtn setImage:PNG_FROM_NAME(@"delAllHistory.png") forState:UIControlStateHighlighted];
[clearnAllBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 9, 0, 13)];
[clearnAllBtn setTitleColor:colorWithHexString(@"0072ff") forState:UIControlStateHighlighted];
[clearnAllBtn setTitleColor:colorWithHexString(@"0072ff") forState:UIControlStateNormal];
UIView *sepLineHistory=[[UIView alloc]initWithFrame:CGRectMake(0, 34.5, SCREEN_WIDTH, 0.5)];
[sepLineHistory setBackgroundColor:[UIColor lightGrayColor]];
[searchHistoryHeaderView addSubview:sepLineHistory];
[searchHistoryHeaderView addSubview:searchHistoryText];
[searchHistoryHeaderView addSubview:clearnAllBtn];
[searchHistoryHeaderView setBackgroundColor:KVIEW_Background_Color];
[searchHistoryText release];
[sepLineHistory release];
return searchHistoryHeaderView;
}
}