簡潔的ios小介面
下午寫寫了個小東西小介面
有需要的可以直接拿過來用 ,簡潔,挺好看,自我感覺;
寫介面其實就是自上而下的在view加空間,注意一下位置就行了
- (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { CGRect screenSize = [[UIScreen mainScreen]bounds]; //無貨物資訊圖片 UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 160, 100)]; image.center = CGPointMake(screenSize.size.width/2,screenSize.size.height/2-15-55); image.image = [UIImage imageNamed:@nocargo.jpg]; image.backgroundColor = [UIColor orangeColor]; [self addSubview:image]; //你還沒有收貨地址label UILabel *noLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 160, 30)]; noLabel.center =CGPointMake(screenSize.size.width/2,screenSize.size.height/2 ); noLabel.text = @您還沒有收穫地址; noLabel.textAlignment = NSTextAlignmentCenter; noLabel.font = [UIFont fontWithName:@Helvetica size:19]; [self addSubview:noLabel]; //請添加新地址label UILabel *addLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 150, 30)]; addLabel.center =CGPointMake(screenSize.size.width/2,screenSize.size.height/2+30); addLabel.text = @請添加新地址; addLabel.textAlignment = NSTextAlignmentCenter; addLabel.font = [UIFont fontWithName:@Helvetica size:15]; [self addSubview:addLabel]; //添加新地址按鈕設定 addAddressBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 150, 30)]; addAddressBtn.center = CGPointMake(screenSize.size.width/2,screenSize.size.height-40 ); [addAddressBtn setTitle:@添加新地址 forState:UIControlStateNormal]; [addAddressBtn addTarget:self action:@selector(addAddressBtnClick) forControlEvents:UIControlEventTouchDown]; addAddressBtn.layer.borderWidth = 1; addAddressBtn.layer.cornerRadius = 5; addAddressBtn.layer.borderColor = [UIColor redColor].CGColor; addAddressBtn.titleLabel.font = [UIFont fontWithName:@Helvetica size:18]; addAddressBtn.titleLabel.textColor = [UIColor redColor]; [self addSubview:addAddressBtn]; self.backgroundColor = [UIColor colorWithRed:238/255.0 green:238/255.0 blue:238/255.0 alpha:1]; ; } return self;}
以上就是第一個頁面的所有內容;
我們來看一下第二張圖吧
xib 中添加控制項實現這個效果三個都是label;設定一下字型什麼的就行 最後加一個小圖片 箭頭
注意在地址中我們用到了富文本label 將【預設】設定為紅色,看第二幅圖;
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@Using NSAttributed String];[str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,5)];[str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6,12)];[str addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(19,6)];[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@Arial-BoldItalicMT size:30.0] range:NSMakeRange(0, 5)];[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@HelveticaNeue-Bold size:30.0] range:NSMakeRange(6, 12)];[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@Courier-BoldOblique size:30.0] range:NSMakeRange(19, 6)];attrLabel.attributedText = str;
本段代碼來自http://www.cnblogs.com/taintain1984/p/3550525.html;
下面是在設定tablecell的代碼;
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *cellIdentifier = @cellIdentifier; NSDictionary *dictionary = [tableArray objectAtIndex:indexPath.row]; TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if(cell==nil) { cell = [[NSBundle mainBundle] loadNibNamed:@TableViewCell owner:nil options:nil][0]; } cell = [cell setCelldictionary:dictionary]; return cell;}
最後有一個地方就是我們寫完tableview的時候是第三幅圖的樣子,後面沒有內容了但是還是有表格線,那我們怎麼辦呢。。
只要加上一句話就夠了
self.tableFooterView = [[UIView alloc]init];