I'm trying to center a UIButton to rootView. I've tried with this code:
self.startNewCross.center = CGPointMake(self.view.center.x, self.startNewCross.frame.origin.y);
but it doesn't work, then I've tried to center the background image to UIButton
self.startNewCross.imageView.contentMode = UIViewContentModeCenter;
but the uibutton is fixed on left. How to move the uibutton?
I've other elements and the I move it without problem
Thanks a lot
You can try this
[self.startNewCross setCenter:self.view.center]
This Will Helps You....
Related
I'm new to ios development and i'm struggling to make something that should be trivial.
I want simple container with background color and single line text inside with padding and i prefer to make it programmatically (no IB).
What i've already tried:
simple UILabel vertical padding is not a problem with fixed height but no horizontal;
also UIView with UILabel as subview - adding background color to UIView and the label is just text sizeToFit;
When i am using UIView with UILabel as subview i've set:
[self.myTestView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
but because i'am using NSLayoutConstraint when i set self.myTestView.translatesAutoresizingMaskIntoConstraints = NO; i don't have proper autoresizing.
If it helps i'am trying this into UICollectionViewCell?
Just for additional information i know this can be achieved with UIButton and using UIEdgeInsets, but i don't want to use UIButton for simple text container.
Does anybody have an idea or direction?
Thanks in advance!
Why you just didn't add constraint to your label inside uiview in IB, with padding what you need?!
http://i.stack.imgur.com/8qTGt.png
I have a UIScrollView, with a UIImageView and UIButton inside of it.
I was reading in the answers here that if I have a single view that contains all of my zoomable content, then I should be fine. The problem is that the button doesn't zoom when the image does.
I thought that what I have would work, since the Scroll View is the zoomable view.
Do I need to create another UIView and put everything in there (and keep the same hierarchy?) ?
Have you checked your Springs and Struts? Look in the size inspector under "autosizing". Those little red lines.. if that doesn't make sense, search for 'auto layout'.
I ended up fixing this by declaring the button in code, and added a UView into the hiearchy. The uiview is a subview of the scroll view, and the imageview is a subview of the uiview. I then added the buttons to the uiview.
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
...
[view addSubview:button];
How to draw graphics on a UIButton UIButtonTypeRoundedRect without subclassing... or do I have no choice? Please note that the graphics around the rounded corners will vary with other functions... so the UIButton cannot interfere... otherwise I could have just used jpg images.
Or can I limit the border of the jpg image around the UIButton?
thx
If I got your question correctly, you need to create an UIButton with an image inside (png or jpg) with rounded corners.
It could be easier if you subclass UIButton (so you can reuse it), but if you don't want to do it, just suppose we have
UIButton *myButton;
pointing to your UIButton with images and other properties correctly setted.
First, don't forget to
#import <QuartzCore/QuartzCore.h>
and then simply set:
myButton.layer.cornerRadius = 5.0f; //or any CGFloat values you need
If it seems not working, check the UIButton "Clip Subviews" property or use:
myButton.clipsToBounds = YES;
I have main UIScrollView with lots off buttons which i create like this:
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom]
every button have an image:
UIImage *fileImage = [UIImage imageNamed:#"sun.png"];
[myButton setBackgroundImage:fileImage forState:UIControlStateNormal];
Buttons count could be more than 500. So i need to remove from UIscrollView invisible buttons with images to save memory ?
I believe in this method i need to calculate when UIscrollview is stopped scrolling and for example 20 images are invisible, then i need to remove them and reduce scroller contentOffset.
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
float bottomEdge = scrollView.contentOffset.y + scrollView.frame.size.height;
}
Maybe some one could give me tips on this. Or even have a good bookmarked tutorial.
I created a similar thing to this using UIViews in a UIScrollView. When the UIScrollView loads, I set the contentView size of the scrollView to be the size of all the views but only loaded the views that can be seen, then when the user scrolls i added the previous/next views and removed the hidden views.
This question helped me: How to implement UIScrollView with 1000+ subviews? especially akosma's answer
I got a small problem with my UIScrollView. I've added the scrollview to my UIView with Interface Builder. I've also added a UIToolbar as a subView (programmatically if it matters) to the view.
Now, my problem is that the scrollview scrolls under the UIToolbar. It doesn't "stop" at the top of the toolbar as it should to. It works if I change the size of the UIView, but that can't be the right thing to do, because then the toolbar becomes non-clickable.
I hope somebody can get me on the right track, thanks! :)
Try doing something along these lines after creating your toolbar:
CGRect scrollFrame = myScrollView.frame;
scrollFrame.size.height = scrollFrame.size.height - myToolbar.frame.size.height;
myScrollView.frame = scrollFrame;