Swift 5:如何以编程方式将图像添加到UIScrollView

Scroll views allow for scrolling and zooming in your iOS App. Today we’re going learn about how to add images to them by taking advantage of their “contentSize” attribute. The content size of a UIScrollView refers to the width and height of its content view. When a UIScrollView’s content size is larger than the phone screen, then scrolling is enabled.

滚动视图可用于在iOS App中滚动和缩放。 今天,我们将学习如何利用图像的“ contentSize”属性向其添加图像。 UIScrollView的内容大小是指其内容视图的宽度和高度。 当UIScrollView的内容大小大于电话屏幕时,则启用滚动。

Step 1: Create a new Xcode project and navigate to ViewController.swift

步骤1:创建一个新的Xcode项目并导航到ViewController.swift

Step 2: Create the UIScrollView and give it the appropriate properties.

步骤2:创建UIScrollView并为其提供适当的属性。

Step 3: Create our UIImageViews and make them subviews of the UIScrollView. Once we do this, our final code looks like:

步骤3:创建我们的UIImageViews,并使它们成为UIScrollView的子视图。 完成此操作后,最终代码如下所示:

Image for post

翻译自: https://medium.com/swlh/swift-5-how-to-programmatically-add-images-to-a-uiscrollview-ee5b97aa2e00

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值