Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new extensions #1097

Merged
merged 4 commits into from
Jun 25, 2018
Merged

Added new extensions #1097

merged 4 commits into from
Jun 25, 2018

Conversation

OrkhanAlikhanov
Copy link
Contributor

Added UIColor(argb:), UIColor(rgb:), UIButton.fontSize, UILabel.fontSize

let color = UIColor(argb: 0xFFAABBCC)
let color = UIColor(rgb: 0xAABBCC)

let label = UILabel()
label.fontSize = 15

let button = UIButton()
button.fontSize = 15

- Parameter rgb: An unsigned 32 bit integer. E.g 0xAA44CC.
*/
convenience init(rgb: UInt32) {
self.init(argb: (UInt32(0xff000000)) | rgb)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DanielDahan You might wonder why I didn't use Int. As far as I remember, using it was causing crash on 32-bit devices. Even on iPhone 4s simulator for example. I can't verify since I don't have 32bit simulator and won't be able to get it soon. Can you please try it with Int or UInt. With UInt32 it works I am sure. But it will fail to compile with Int32 when a large interger value is used. e.g UIColor(argb: 0xFFFFFFFF)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Does The reason I believe UInt32 works over Int32 is because UInt32 is unsigned which means all values are positive and it could hold a larger range, where Int32 is signed and therefore holds a smaller positive range but both negative and positive. So please use UInt32.

Copy link
Contributor Author

@OrkhanAlikhanov OrkhanAlikhanov Jun 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sure, I know. I meant larger in terms of positivity. Thank you for explaining :)

public extension UIButton {
/// Convenience way to change titleLabel font size.
var fontSize: CGFloat {
set {
Copy link
Member

@daniel-jonathan daniel-jonathan Jun 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the setter and getter, please you use this format:

get {
   return ...
}
set(value) {
   ... = value
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to use value or I can use for example size?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does set get order matter?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both order and name matter. As it is consistent with the entire framework. Also, helps to search everything easily when it is the same naming and format.

@daniel-jonathan daniel-jonathan merged commit d89a693 into CosmicMind:development Jun 25, 2018
@daniel-jonathan
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants