last day (14 days later) » 

6:32 PM
0
Q: Swift / cornerRadius and masksToBounds lets UIImageView disappear

David SeekI have a UITableViewController with a UIImageView. The content is loaded with the following simple code. @IBOutlet weak var avatarImageView: UIImageView! override func viewDidLoad() { super.viewDidLoad() updateUI() } func updateUI() { backendless.userService.currentUser.retrieveP...

 
this is just a guess but can you just change width/2 to width/2.0 and run once? it might be a problem of auto layout constraints also..
 
@M.K. no difference on width/2.0 - the UIImageView still doesn't display
 
put a debugger and check whats the width just before this line..if it has value or not. because this code works everywhere. i don't think there is any problem with the code. i think problem with the sequence of the code and correct place to call it.
 
print("width = \(avatarImageView.frame.size.width)") sais 1.000 .... but i did set constraints to 150.... hmmmmm you may be right on your guessing...
but why is that?? Width Equals 120... why is it 1.000 with print("width = \(avatarImageView.frame.size.width)") inside func updateUI()?
i even checked.... see image
 
i guess this is because its inside UITableViewController. can you try same with normal UIViewController with a image and same code?
 
6:32 PM
no need to try. it's working somewhere else in my code within UIViewController and UITableView.
hey. any idea was causes that issue?
 
then i was right.
as you added the image view to a UITableViewController, it means you have added it to a tableview
 
yes
avatarImageView.frame.size.width = 120
avatarImageView.layer.cornerRadius = avatarImageView.frame.size.width/2.0
avatarImageView.layer.masksToBounds = true
this solved the issue
now it is working
 
i knew it
i was just about to tell you the same
constraint will not work on a image inside uitableview
you have to set frame
 
but i dont get why. because it did set constraints... why is the behavior different
hm okay
 
should i post the answer?
 
6:35 PM
so. in genereal?
 
to change frame
 
inside a tableview the uiimageview has be set?
 
in general you should use uiviewcontroller
 
and constraints are not working?
 
yes
 
6:36 PM
but just within tableviewcontroller or in general with tableview?
 
except uitableview cell prototype if you add any UIView subclass to table view
it treats it as either header view or footer
its general with tableview
 
okay
well. my problem is solved. feel free to post
 
ok thanks
 
i'll accept as ap
thank you.
have a good night
 
sure welcome..
good night
 
6:44 PM
by the way
this other dude was right
after viewDidAppear the constraints are set
 
then its correct
 
i guess his solving is better since i don't have to hardcode the constraints in code after i did in interface builder
 
obviously
i think i should delete my answer...we should go in right direction..but its best practice if you use normal view controller with a tableview.
but one think i want to say
if you call everything in viewdidappear it will flick a slide while it will display...like the frame change or the image display will be visible when you do it in did appear.
try once in will appear otherwise use normal controller.
 

last day (14 days later) »