将 UIImageView 添加到 UIScrollView
Add UIImageView to UIScrollView
希望有人能指出这有什么问题。
我的故事板有一个 UIScrollView
名为 timelineScrollView
和一个 UIImageView
名为 imageviewtest。
我正在创建一个图像,它是一条简单的直线。如果我将它添加到 UIImageView
它显示正常。但是,如果我将它添加到 UIScrollView
,则不会显示任何内容。
如何让它显示在 UIScrollView
中?
func drawingTest(){
let drawing = DrawingHelper()
let imageSize2 = CGSize(width: 100, height: 60)
let fromPoint: CGPoint = CGPoint(x: 0, y:0)
let toPoint: CGPoint = CGPoint(x: 50, y:0)
imageviewtest.image = drawing.drawLine(fromPoint, toPoint: toPoint, imageSize: imageSize2)
var imageView = UIImageView()
var image = drawing.drawLine(fromPoint, toPoint: toPoint, imageSize: imageSize2)
imageView.image = image;
var scrollViewAreaSize = CGSize(width: 100, height: 60)
timelineScrollView.contentSize = scrollViewAreaSize
timelineScrollView.addSubview(imageView)
}
为您的图像视图设置适当的框架或使用您的图像初始化 UIImageView:
var image = drawing.drawLine(fromPoint, toPoint: toPoint, imageSize: imageSize2)
var imageView = UIImageView(image:image)
This method adjusts the frame of the receiver to match the size of the
specified image.
希望有人能指出这有什么问题。
我的故事板有一个 UIScrollView
名为 timelineScrollView
和一个 UIImageView
名为 imageviewtest。
我正在创建一个图像,它是一条简单的直线。如果我将它添加到 UIImageView
它显示正常。但是,如果我将它添加到 UIScrollView
,则不会显示任何内容。
如何让它显示在 UIScrollView
中?
func drawingTest(){
let drawing = DrawingHelper()
let imageSize2 = CGSize(width: 100, height: 60)
let fromPoint: CGPoint = CGPoint(x: 0, y:0)
let toPoint: CGPoint = CGPoint(x: 50, y:0)
imageviewtest.image = drawing.drawLine(fromPoint, toPoint: toPoint, imageSize: imageSize2)
var imageView = UIImageView()
var image = drawing.drawLine(fromPoint, toPoint: toPoint, imageSize: imageSize2)
imageView.image = image;
var scrollViewAreaSize = CGSize(width: 100, height: 60)
timelineScrollView.contentSize = scrollViewAreaSize
timelineScrollView.addSubview(imageView)
}
为您的图像视图设置适当的框架或使用您的图像初始化 UIImageView:
var image = drawing.drawLine(fromPoint, toPoint: toPoint, imageSize: imageSize2)
var imageView = UIImageView(image:image)
This method adjusts the frame of the receiver to match the size of the specified image.