UI

2018-07-19  本文已影响10人  英雄出少年
viewWithTag
 UIView *view = [self.view viewWithTag:100];
 //内部原理 
    1.首先会跟自己匹配
    2.如果自己不匹配,会遍历所有的子控件;首先会遍历subViews数组中第0个控件,如果不匹配,会遍历这个控件的子控件,依次遍历
    3.如果都不匹配,会返回nil
界面初始化方法
frame、bounds、center 区别
  UIView *redView = [[UIView alloc] init];
    redView.backgroundColor = [UIColor redColor];
// 修改位置和尺寸,以父控件左上角为坐标原点
    redView.frame = CGRectMake(100, 100, 200, 100); 
// 修改尺寸,以自己左上角为坐标原点
//    redView.bounds = CGRectMake(0, 0, 300, 200); 
// 修改位置,以父控件左上角为坐标原点
//    redView.center = CGPointMake(200, 200); 
    
    [self.view addSubview:redView];
UIImageView
    //第一种方式
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"2"]];
  // initWithImage:会根据传入的图片创建imageView,并且imageView的尺寸等于图片的尺寸
    [self.view addSubview:imageView];

  //第二种方式
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.image = [UIImage imageNamed:@"2"];
    imageView.frame = CGRectMake(0, 0, imageView.image.size.width, imageView.image.size.height);
    [self.view addSubview:imageView];

// oc语法规定:不能直接修改oc对象结构体属性的成员
  CGRect tempFrame = imageView.frame;
   tempFrame.size = imageView.image.size;
  imageView.frame = tempFrame;
 //带有scale:图片有可能会被拉伸
 UIViewContentModeScaleToFill,
 UIViewContentModeScaleAspectFit,
 UIViewContentModeScaleAspectFill,
 
// 不带有Scale:显示出来的图片不会被拉伸,保持图片原来的宽高比例
 UIViewContentModeCenter,
 UIViewContentModeTop,
 UIViewContentModeBottom,
 UIViewContentModeLeft,
 UIViewContentModeRight,
 UIViewContentModeTopLeft,
 UIViewContentModeTopRight,
 UIViewContentModeBottomLeft,
 UIViewContentModeBottomRight,
 */



方法1
// ios8 出现布局边缘
self.tableview.separatorInset = UIEdgeInsetsZero;
cell.layoutMargins = UIEdgeInsetsZero;

方法2
/* 
1.取消tableview的分割线
2.设置tableview的背景色为分割线的颜色
3.setFrame 设置frame之前 ,把高度减 10
4.补回分割线的高度
*/

-(CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{
   return 60 + 10;
}

- (void)setFrame:(CGRect)frame {
    frame.size.height -= 10;
    frame.origin.y  +=10;
    frame.origin.x += 10;
    frame.size.width -= 20;
      [super setFrame:frame];
}

cell2.png cellwidth.png display.png
contentSize、contentOffset、contentInset
contentSize:内容 滚动范围
内容无限大 ,可视区域
contentOffset: 偏移量 ,tableview顶点与内容顶点的距离
额外的滚动区域,超出内容可以滚动多少,额外滚动区域不属于内容
tableview默认会滚动到最上面
contentInset: 内边距

上一篇 下一篇

猜你喜欢

热点阅读