I set the border for my layer by adding the following line of code:
layer
[self.avatar.layer setBorderColor:[UIColor whiteColor].CGColor];
How to change alpha only on border and not on avatar object?
avatar
Use UIColor +colorWithWhite:alpha:
UIColor
+colorWithWhite:alpha:
[self.avatar.layer setBorderColor:[UIColor colorWithWhite:1.0f alpha:0.5f].CGColor];
If you need a color other than white, use +colorWithRed:green:blue:alpha: as mentioned by user +colorWithRed:green:blue:alpha: .
+colorWithRed:green:blue:alpha:
For version Swift-3
let opacity:CGFloat = 0.6 let borderColor = UIColor.white self.view.layer.borderColor = borderColor.withAlphaComponent(opacity).cgColor
Use [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.5] . A value of 1.0 for red, green, and blue makes the color white, and you can change the alpha to whatever you want.
[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.5]
With -colorWithAlphaComponent: you can easily do this for any borderColor
-colorWithAlphaComponent:
borderColor
CGFloat opacity = 0.5f; self.avatar.layer.borderColor = [borderColor colorWithAlphaComponent:opacity].CGColor;
Source: https://habr.com/ru/post/1200772/More articles:Error ASIHTTPRequest CFRunLoopRun () - iosHow to restart / reset jQuery animation - javascripthttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1200768/javafx-multiple-buttons-to-same-handler&usg=ALkJrhg_yEd0S_mvVqTmYB2fQL0tRWL8-QWhy is NetBeans warning about passing int [] to vararg? - javaImport DateTime using Nemo / Alice package - datetimeCan't save the baud rate settings? - commandXcode compilation error: ld: character (s) not found for x86_64 architecture clang - iosConnection timed out. The waiting period that has elapsed during the phase after entry - c #How can cassandra take a snapshot using a hard link? - linuxHow can I prevent jsx watch from compiling swap files? - reactjsAll Articles