IOS開發過程中的學習的知識(1)

IOS新手,在開發中遇到的一些細節問題,總結一下,以免後來用到。

總結一下控件。

一、UITableview
1、分割線左邊短一塊
系統自帶的控件的分隔符是左邊短一塊的,詳見短信的界面。爲了使其與屏幕一邊長,需要加入如下代碼
(1)如果該界面是UITabViewController,則需加入
- (void)viewDidLayoutSubviews
{
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
    }
    
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
    }
}
-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}
(2)如果只是UITableView控件,先在viewDidLoad中加入
if ([_table respondsToSelector:@selector(setSeparatorInset:)]) {
[_table setSeparatorInset:UIEdgeInsetsZero];
}
    if ([_table respondsToSelector:@selector(setLayoutMargins:)]) {
        [_table setLayoutMargins:UIEdgeInsetsZero];
}
 然後
-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}
2、去掉多餘的項
UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor clearColor];
    [_table setTableFooterView:view];
    [_table setTableHeaderView:view];
3、下拉刷新
[_table addSubview:UIRefreshControl];//針對單獨的UITableView控件,UITableViewController有一個RefreshControl的私有成員。
二、UILabel
1、自動換行的Label
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
    _attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15.0], NSParagraphStyleAttributeName:paragraphStyle};
CGSize sizedate = [_label.text boundingRectWithSize:CGSizeMake(self.view.frame.size.width-16, 999) options:NSStringDrawingUsesLineFragmentOrigin attributes:_attributes context:nil].size;
            CGRect rectdate =_label.frame;
            rectdate.size.height = sizedate.height;
            _label.frame = rectdate;
然後再將這個Size賦給Label;
三、UINavigationController
1、可以通過viewControllers訪問其所有View,根節點爲0;

四、控件佈局

1、可以用setFrame來做,Frame是相對於父控件的座標參數,而bounds是相對於界面的。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章