美文网首页GXiOS
iOS开发--UIImageView.Frame设置的四种方式

iOS开发--UIImageView.Frame设置的四种方式

作者: Caesar_62dd | 来源:发表于2019-05-05 22:01 被阅读10次

    方式一:

    UIImageView *imageView = UIImageView.new;
    imageView.image = [UIImage imageNamed:@"1"];
    //CGRectMake方法
    imageView.frame = CGRectMake(100,100,200,400);
    //强制类型转换
    imageView.frame = (CGRect){{100,100},{200,400}};
    

    方式二:

    UIImageView *imageView = UIImageView.new;
    UIImage *image = [UIImage imageNamed:@"1"];
    imageView.frame = CGRectMake(100,10, image.size.width, image.size.height);
    //设置图片
    imageView.image = image;
    

    方式三:

    UIImage *image = [UIImage imageNamed:@"1"];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100,10, image
    .size.width, image.size.height)];
    

    方式四:

    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithNamed:@"1"]];
    //改变位置
    imageView.center = CGPointMake(self.view.frame.size.width*0.5, self.view.frame.size.height*0.5);
    
    

    相关文章

      网友评论

        本文标题:iOS开发--UIImageView.Frame设置的四种方式

        本文链接:https://www.haomeiwen.com/subject/dhukoqtx.html