UILabel Circle Background [duplicate] - swift

This question already has answers here:
Attempting to mask a circle around an image not working
(2 answers)
Closed 2 years ago.
I want to make the label's backround full circle.
i searched and find out
numLabel.layer.masksToBounds = true
numLabel.layer.cornerRadius = numLabel.bounds.width / 2
on iphone it is fine
on ipad, firsttime it is just a corner radius rectangle, when i move tableview up and down, in anotherwords, cell view gets out of the main view and gets back in, it becomes a fine circle.
i wonder, what is the mistake i am doing ?
edit : numLabel is inside TableViewCell / TableViewController / NavigationController / splitViewController
and it has its own tableViewCell class. and that code is run From layoutsubviews()
numlabel width and height is equal by contraints

you should never call layoutSubViews directly
override layoutSubViews, don't forget to call super and then put your code there.

Related

ARSCNView Corner Radius not showing

I have a corner radius on my ARSCNView as below;
override func viewDidLayoutSubviews() {
sceneView.layer.cornerRadius = 8
sceneView.layer.masksToBounds = true
sceneView.clipsToBounds = true
}
However, it is only showing when you enter app in background as illustrated below;
As soon as the app is in the foreground the corner radius goes back to 0.
Ive tried adding in ViewDidLoad & ViewWillAppear no success
I just tried with just
sceneView.layer.cornerRadius = 8
without masksToBounds and clipsToBounds and it worked for me.
If you're sceneView is inside another view or the root view of your view controller, check the background of that view and make sure it's something noticeable.
Maybe the sceneView itself is larger than the phones screen. Check the frame size or the layout constraints and make sure they are not causing the sceneView to stretch outside the phone screen edges.
I hope this answers your question.

Deleting shape in drawRect method? - ObjectiveC [duplicate]

This question already has an answer here:
Resizing a rectangle drawn in drawRect
(1 answer)
Closed 9 years ago.
I have a rectangle drawn using drawRect method. I need to update this rectangle.
But I don't know how to create an instance of it.
I need to delete the previously drawn rectangle (or) change the frame of the previously drawn rectangle.
How can I do this?
The system keeps track of which part of your view it thinks is “dirty” (needs to be drawn). When the view is first created, the entire view is dirty. When you send setNeedsDisplay to the view, that marks the entire view dirty. If you send setNeedsDisplayInRect:, the specified CGRect is added to the part of the view that is considered dirty.
Before the system sends your view the drawRect: message, it clears the entire dirty region of the view to the view's background color. So if you send setNeedsDisplay to your view when you want to erase the previously drawn rectangle, you don't need to worry about erasing your rectangle in drawRect:; the system has already erased it for you. But it also means that if there was anything in the dirty region that you didn't want erased, you must draw it again before returning from drawRect:.

How to find dynamic centre of iOS device screen [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
iOS SDK: Moving the button into the center of screen by code
UIImageView. Zoom and Center to arbitrary rectangle. Can’t determine correct center on screen
I'm trying to centralise an UIActivityIndicator in a UIWebView(which in turn is a subView of a UIScrollView, which also has a UIToolbar element to the left - although the left-toolbar isn't always visible)
Similar questions have been asked before, but the point is in finding the center "dynamically" i.e. on change of orientation as well as presence or absence of the left toolbar.
What's the best approach? Is there any better way to do this than overriding the method shouldAutorotateToInterfaceOrientation?
Center of what btw?
You can access the UIViewController's center as self.view.center
or in your case, UIWebView's center as yourwebView.center
And by giving it resizing elements of top left, activityindicator would center it-selves always.
EDIT :
If you want center of the screen that would be gained by frame like
Consider activity indicator of width and height 30, 30.
(([UIScreen mainScreen].bounds.size.width)/2 - 15, ([UIScreen mainScreen].bounds.size.height)/2 - 15, 30, 30);
Then, set autoresizing elements to none.
Go to size Inspector and remove all the arrows from the Auto-sizing feature.
There can be not general solution to your question. This is because only you know what element in your view you want to ignore or not. The view always stays the same, no matter what element you add to it. So, I suggest getting a rectangle for the part of the view you consider as clear/empty/available and setting your loading indicator in that. Just get the view's whole frame (self.view.frame.size.height) and substract any elements from there. For example
MyIndicator *indicator = [[MyIndicator alloc] initWithFrame:CGRectMake(self.toolbar.frame.size.width + self.toolbar.frame.origin.x, self.topBar.frame.size.height + self.topBar.frame.origin.y, self.view.frame.size.width - self.toolbar.frame.size.width - self.toolbar.frame.origin.x, self.view.frame.size.height - self.topBar.frame.size.height - self.topBar.frame.origin.y)];

How to create resizable view with handlers on sides to stretch or resize in ios? [duplicate]

This question already has an answer here:
Changing View size using user touch input
(1 answer)
Closed 7 years ago.
I am creating an app where user touch the screen and places a rectangle view on screen which he can move or resize by touching its corners like any other crop view . I have done this functionality but i want eight handlers on the sides of that rectangle so that user can use that handlers to resize it. Now i am unable to create such functionality . I tried to add eight buttons as subview on that rectangle view but when resizing when that view increase its size than all eight buttons just change their positions . can anybody help me with this functionality ?
Thanks in advance
Hi i got the answer from here . here is a great class for making resizable view. Great work by the developer
Create resizable view in ios with UITouch
To do this you are going the right way about it.
You need to create a custom view that positions these eight handles depending on the size of the view. When the view changes size you then need to reassess where those handles are so maybe have a function thats called when the view is resized and in here you change the location of each handle just by changing its x and y origin depending on the view size.

Problem regarding draw image [duplicate]

This question already has an answer here:
Closed 11 years ago.
Possible Duplicate:
How to set this Layout in iPhone need Some help
I draw image in imageview.
I have one image view and Button is there.
When i draw something it show like this,
I dont wan't to show drawing on that button.
How can i do that?
There are 2 approaches:
1) You can do this IB:
Drag your UIImageView in IB to bottom of your stack subviews of view where your UIView (where you are drawing) is placed.
2) You can do this in code:
Push your view on the top of views using following method
- (void)bringSubviewToFront:(UIView *)view
For example:
UILabel * labelgreen;
[labelgreen.superview bringSubviewToFront:labelgreen];