how to draw a custom UIView with a visible border and transparent interior (i.e. just draw the border) - iphone-sdk-3.0

The frame size is adjustable so using a png for background is not an option

Set background color of your view to clearColor, then either set border property to view's layer (see here how-to), or in view's drawRect: method stroke a rectangular path on the border of the view

Related

Update subview's corner radius when Cell's size change

I have a VC (MainVC), inside hold a property UICollectionView. This CollectionView has a custom layout (UICollectionViewFlowLayout).
I also have a setting, which can change some of this custom layout's property (number of items per page).
Now, inside the collectionViewCell, I have an image, which desired to have rounded rect. So I use this:
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
self.imageView.layer.cornerRadius = self.imageView.frame.size.width / 2;
}
However, when I apply the setting, change the custom flow layout, the cell doesn't re-draw and the drawRect: never got called => Result: not a rounded rect border for the imageView.
What should I do to apply new layout (resize the cell with custom layout) and remain rounded rect for the cell's imageView?

Resizing UIView frame rect, do the sublayers resize?

I have a UIView and I change the frame size but I dont think the layer is resizing. How does one resize the layer with the frame without overriding layoutSubviews?

NSScrollView with fixed background texture

I have an IKImageBrowserView that is the document view of an NSScrollView. How can I set a background image (a texture) so that the background remains fixed when the user scrolls.
I have tried a variety of things but either they just don't work or it doesn't remain fixed.
I have tried making the IKImageBrowserView and NSScrollView transparent, but this doesn't work, the background is black.
I have tried adding the texture as the background layer of the image browser:
NSColor* browserBackgroundColor = [NSColor colorWithPatternImage:[NSImage imageNamed:#"linenTile"]];
CALayer *layer = [CALayer layer];
[layer setBackgroundColor:[browserBackgroundColor CGColor]];
[self.imageBrowserView setBackgroundLayer:layer];
It remains fixed when scrolling down, but when scrolling up. This is the closest I have got it.
If your scrollView is full screen, you can just set you image to be the background of your self.view, and then set the background of your scrollView transparent.
Or you can just add a separate NSView beneath your scrollView, make it cover the same area as your scrollView, and set its background.
Finally got the combination correct.
Subclass NSScrollView and draw the pattern image in drawRect:
- (void)drawRect:(NSRect)rect {
[[NSColor colorWithPatternImage:[NSImage imageNamed:#"linenTile"]] set];
NSRectFill(rect);
}
Set the background of the document view to clear (for IKImageBrowserView like this):
[self.imageBrowserView setValue:[NSColor clearColor] forKey:IKImageBrowserBackgroundColorKey];
And also the Draw Background check box in interface builder on the scroll view must be unchecked. Or set the value to NO in code.
If you want the pattern to scroll with the content. Don't subclass the NSScrollView and just set the background color of the scrollview to the pattern, and the background color of the document view to clear.
Subclassing and -drawRect: is unnecessary, simply use the backgroundColor property of NSScrollView. The docs say "This color is used to paint areas inside the content view that aren’t covered by the document view."
scollView.backgroundColor = [[NSColor colorWithPatternImage:[NSImage imageNamed:#"linenTile"]] set];

Draw UIBezierPath on UIImageView

How can i draw UIBezierPath on UIImageView? I have tried following code but when UIImageView's image is nil then I am only able to see the path, when I add the image this path is overlapped with the UIImageView's image. I want to draw the path above the UIImageVIew's image.
Yes you can draw bezierpaths in uiimageview by clling a draw method like DrawRect in uiview.
Try adding a transparent UIView on top of your UIImageView.
Make a UIView subclass for this transparent view.
Override drawRect method in this subclass.
stroke all the paths you want to draw.
Please get back to me if you want sample code for this.

Can I change bottom border line color of textfields in objective c?

I want to change border color of textfield.
textField1.backgroundColor=[UIColor redColor];
this code is change all border color (up, bottom, right, left border). But I want to set only bottom border color. Is this possible?
Thanks.
You cannot change the border color of the textfield, instead you get a image with the design you want and set it as your textfield's background image