ios - 如何快速更改页面控制点的大小和间距?
问题描述
我想像图像一样自定义页面控件。
我已经搜索过了,但只有交易规模。
我想改变宽度,高度,间距。
我怎样才能做到这一点?
我试过这个
class DefaultPageControl: UIPageControl {
override var currentPage: Int {
didSet {
updateDots()
}
}
func updateDots() {
let currentDot = subviews[currentPage]
subviews.forEach {
$0.frame.size = ($0 == currentDot) ? CGSize(width: 16, height: 4) : CGSize(width: 8, height: 4)
$0.layer.cornerRadius = 2
}
}
}
但是如何改变距离?
解决方案
@oddK您可以尝试以下答案吗?这是我的假设。
class DefaultPageControl: UIPageControl {
override var currentPage: Int {
didSet {
updateDots()
}
}
func updateDots() {
let currentDot = subviews[currentPage]
let spacing = 5.0
subviews.forEach {
$0.frame = ($0 == currentDot) ? CGRect(x: 0, y: 0, width: 16, height: 4) : CGRect(x: spacing, y: 0, width: 8, height: 4)
//$0.frame.size = ($0 == currentDot) ? CGSize(width: 16, height: 4) : CGSize(width: 8, height: 4)
$0.layer.cornerRadius = 2
}
}
}
推荐阅读
- amazon-s3 - 在 s3 pyspark 作业中创建单个镶木地板文件
- c++ - 将 _bstr_t 对象传递给期望 BSTR 作为参数的函数是否安全?
- javascript - 如何根据反应中的另一个值在布尔值之间切换
- html - 尝试单击“赞”按钮时出现错误 此页面无法正常工作 HTTP 错误 405
- python - dynamodb 条件更新项(客户端)
- java - 使用java 8将for循环转换为流
- android - 尝试在空对象引用上调用虚拟方法 'android.os.Handler android.app.FragmentHostCallback.getHandler()'
- java - 如果您不知道某些元素是否存在,什么是好的 Selenium 策略?
- javascript - 数组是在函数中定义的,但是当返回它时,它会打印出 undefined
- html - 如何在 spring 控制器部分更改 modelandview 的视图内容?