创建和管理常数的简单方法
通常,我首先声明常数,然后使用某种方法设置其设置。但是,编写一种声明常数和变量的简单方法是安全的吗?
例如,我创建了这样的方法 - 到目前为止可以正常工作:
func textSettings(labelName: String, text: String, color: UIColor, fontSize: Int, xPosition: CGFloat, yPosition: CGFloat) {
let labelName = UILabel(frame: CGRect(x: 0, y: 0, width: 0, height: 21))
labelName.textAlignment = .center
labelName.text = text
labelName.textColor = color
labelName.font = labelName.font.withSize(CGFloat(fontSize))
labelName.sizeToFit()
labelName.layer.position.x = xPosition
labelName.layer.position.y = yPosition
UIScrollView.addSubview(labelName)
}
但是使用它安全吗?创建对象的过程是否有严重的缺点?
Usually I first declare constants and then set their settings using some method. But is it safe to write a simple method that declare constants and variables?
For example, I create such method - that works fine up to now:
func textSettings(labelName: String, text: String, color: UIColor, fontSize: Int, xPosition: CGFloat, yPosition: CGFloat) {
let labelName = UILabel(frame: CGRect(x: 0, y: 0, width: 0, height: 21))
labelName.textAlignment = .center
labelName.text = text
labelName.textColor = color
labelName.font = labelName.font.withSize(CGFloat(fontSize))
labelName.sizeToFit()
labelName.layer.position.x = xPosition
labelName.layer.position.y = yPosition
UIScrollView.addSubview(labelName)
}
But is it safe to use it? Does such process of creating objects has serious drawbacks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您注意到这一点时,这是绝对可能的:
AddSetTingsLabel
会更清楚。This is absolutely possible, as soon as you note this :
addSettingsLabel
would be clearer.