Border in a UIButton - objective-c

I dragged A round rect button into the nib and set a background image for the button. However, the image didn't fill up the whole space, it left out a narrow border on the sides of the button. How do I get rid of this border? Thanks.

if you want to use a custom background image for the UIButton, you should change the button type to UIButtonTypeCustom instead of UIButtonTypeRoundedRect.
(you can do this in the Interface Builder as well)

Related

Create iOS 7 UIButton With Text And Image Using Autolayout

Using Autolayout and Interface Builder with the target device being iOS 7 iPhones, how do I create three of these kind of UIButtons that have an image, a divider line and text? The 3 images for each of the buttons all have the same size. The lines and text in one button must line up with the other buttons' line and text (left align the text). Things can't go crazy if the phone is turned to landscape. All buttons are the same constant size.
The buttons are part of a home screen layout which has a logo at the top and so on. When one taps one of the buttons, the app does something.
One thought was to create a button with no text, put a label on top, a thin view for the line on top, and the uiimageview on top. Maybe explicit layout constraints are not even needed? Maybe a containing view is needed for the "button" contents to keep the "button" pieces together?
Image+text can be achieved using UIButton only without adding any autolayout constraints. You set both image and text using -setImage:forState and -setTitle:forState:, and then adjust button insets using *Insets properties. To set the insets properly, play with this great test project: https://github.com/jrturton/ButtonInsets (it's not quite clear from the docs how to use them simultaneously, and this test app should give you the idea).
As for the separator, I'd recommend adding it directly to your images.
But if you don't want to stick to the UIButton and its insets, you can subclass UIView, add 2 UIImageViews (the actual image and the separator), a UILabel, and throw in a couple of constraints. To make the view clickable, you attach a UITapGestureRecognizer to it.

Adding a UIView as a subview to UIImageView

I am working on creating a color picker for "iOS". I am using this project, since it does what i want: "This"
I want to create a moveable circle (UIView) on top of the palette (UIImageView).
What I want to do is, while users move the circle, take the touch point and call the method getPixelColorAtLocation(); and change the background color of the circle to the color on current point. (Seen on most of the color palette/wheels)
The method getPixelColorAtLocation() is available on a child view. I created a circle with UIView on parent view, the problem is I cant call to getPixelColorAtLocation() from parent view.
My question is, Is there anyway to add a UIView as a subView to UIImageView. If I cant, what choices do I have to achieve what I want?
Yes you can do this.
[myImageView addSubview:sampleView];
An image view is just a subclass of UIView, so you can add subviews to it however you'd like. If there's a reason why you can't do so, then you can always make it a subview of the image view's superview, move it to the front, and then use convertPoint:toView: to convert to the image view's coordinate system, then get the pixel color.

How to set an image to a NSButton to be resized along with the button?

I have an image (3width x 15height, the first and last pixels are rounded on the corners), and I want to create a button (the height of the button is always the same, 15px, but the width changes) that uses this image no matter what size it is, kinda like UIEdgeInsets on iOS.
I've tried to use [[button cell] setImageScaling:NSImageScaleAxesIndependently]; but the image gets distorted and loses quality.
How can I do this on OSX? Thanks!
You could probably create a custom subclass of NSButtonCell and use the Application Kit's NSDrawThreePartImage() function in the cell's drawInteriorWithFrame:inView: method.
For more info on how to use NSDrawThreePartImage(), see Cocoa Drawing Guide: Drawing Resizable Textures Using Images.
If it's possible to set this in graphical interface > Attribute Inspection > Button section Background

UIImageView overlapping effect inside a UIView

Check this URL http://krystalrae.com/
Scrolling down you will see a girl's cloths are changing on mouse wheel scrolling.
I have to create a iPad application where 3 images will appear likewise. The difference will be that in my case image change will occur horizontally rather than vertically in website. Also, i have to make it inside UIView with events touchesBegan, touchesMoved, touchesEnded and touchesCancelled
Help will be appreciated.
Thanks.
From your comment I gather that the problem is the resizing of the images in UIImageView when changing the bounds of the view.
You can set the contentMode of the image view to something else. The default is UIViewContentModeScaleToFill which is not what you want.
You could, for example, set the lower image view to UIViewContentModeBottom, and the upper image view to UIViewContentModeTop.
Don't forget to make sure your image views have sett the property maskToBounds set as YES.

Interface Builder UIButton with Image Rounded Corners Gone

Using Interface Builder I have a UIView with a number of UIButtons as subviews. In IB all of the button types are set to Rounded Rect and each button uses an image from the image drop down box. The images are square and the size of the rounded rect UIButton is the same as image. The images are png's and they are from b&w photo's.
The issue is the UIButton rounded corners are gone and everything is square in IB and when running under the simulator.(no hardware yet) I was hoping the button drawRect would crop the image and preserve the rounded rect look. Is there a way to do this? in IB?
Appreciate the help.
Make sure that Clip Subviews are checked in IB. It's in the Attributes Inspector under the View section.