1. 程式人生 > >簡潔的ios小界面

簡潔的ios小界面

icon sin control .html order value nor uila normal

下午寫寫了個小東西小界面

有須要的能夠直接拿過來用 ,簡潔,挺好看,自我感覺;

技術分享技術分享技術分享

寫界面事實上就是自上而下的在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];
        
        //加入新地址button設置
        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];

self 是tableview。


其它的就沒什麽了,主要是為了幫忙,寫了兩個界面。記錄一下不熟練的地方。

界面代碼下載地址:http://download.csdn.net/detail/u010123208/8013673


簡潔的ios小界面