【发布时间】:2014-10-12 19:15:19
【问题描述】:
我创建了一个分页 UIScrollView,其中包含每个页面上的标签。我怎样才能像图片中那样降低标签之间的边距,然后仍然能够滚动?
目前我的导航栏如下所示。您可以向右滑动到下一页并获取下一个标签。
我想要的是这样的东西,边距很小,而且仍然可以滑动。
viewDidLoad 代码
//Category ScrollView
categoryScrollView = UIScrollView(frame: CGRectMake(0, self.navigationController!.navigationBar.frame.height-38, self.view.frame.width, 38))
categoryScrollView?.contentSize = CGSizeMake(self.view.frame.width, 38)
categoryScrollView?.delegate = self
categoryScrollView?.pagingEnabled = true
self.navigationController?.navigationBar.addSubview(categoryScrollView!)
categoryArray = NSArray(objects: "Book", "Elektronik")
var textWidth = 0
for val in categoryArray!
{
var textLabel: UILabel = UILabel()
textLabel.textAlignment = NSTextAlignment.Center
textLabel.text = val as NSString
textLabel.frame = CGRectMake(CGFloat(textWidth), 0, categoryScrollView!.frame.width, categoryScrollView!.frame.height)
categoryScrollView?.addSubview(textLabel)
textWidth = textWidth + Int(textLabel.frame.size.width)
if textWidth > Int(self.view.frame.width) {
categoryScrollView?.contentSize = CGSizeMake(CGFloat(textWidth), categoryScrollView!.frame.height);
}
}
【问题讨论】:
标签: ios objective-c iphone swift uiscrollview