Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to add a border style to a UITableView? (Not BorderColor/BorderWidth)

Is it possible to add a border style to a UITableView?

Not just bordercolor and borderwidth.

For example a grooved border style?

like image 242
Popeye Avatar asked Mar 29 '12 08:03

Popeye


3 Answers

Hey You can give border to your views using CALayer which is available in QuartzCore Framework

Following link will help you to understand CALayer in detail.

Introduction to CALayers Tutorial

For example from the above link,

// Import QuartzCore.h at the top of the file
#import <QuartzCore/QuartzCore.h>

// In viewDidLoad add the following lines
self.view.layer.backgroundColor = [UIColor orangeColor].CGColor;
self.view.layer.cornerRadius = 20.0;
self.view.layer.frame = CGRectInset(self.view.layer.frame, 20, 20);


CALayer *sublayer = [CALayer layer];
sublayer.backgroundColor = [UIColor blueColor].CGColor;
sublayer.shadowOffset = CGSizeMake(0, 5);
sublayer.shadowRadius = 5.0;
sublayer.shadowColor = [UIColor blackColor].CGColor;
sublayer.shadowOpacity = 1.0;
sublayer.frame = CGRectMake(30, 30, 128, 192);
[self.view.layer addSublayer:sublayer];

Though above code will not give you exact grooved effect. But you can try with it.

like image 141
Devang Avatar answered Nov 10 '22 03:11

Devang


Try to this code may be helped you....

Written on this code in your view did load methods and import the QuartzCore framework in the your .h file or .m file.

[myTBL.layer setBorderWidth: 1.0];
[myTBL.layer setCornerRadius:8.0f];
[myTBL.layer setMasksToBounds:YES];
[myTBL.layer setBorderColor:[[UIColor blackColor] CGColor]];

Happy coding.....

like image 6
Vikas S Singh Avatar answered Nov 10 '22 05:11

Vikas S Singh


The most flexible way is to make your UITableView a subview of a UIImageView and use a stretchable image to render the border styling. Inset your UITableView within the UIImageView to give the required space for your border on all sides.

Create a small square image as a PNG with a transparent background and any etching, shadow, or border style that you want.

Then turn it into a stretchable image using the method below. This takes an image name and returns a stretchable image that will preserve your styling when you resize it:

- (UIImage*)makeStretchableImageNamed:(NSString*)imageName
{
    UIImage *image = [UIImage imageNamed:imageName];
    CGSize size = image.size;
    image = [image stretchableImageWithLeftCapWidth:size.width / 2.0f topCapHeight:size.height / 2.0f];

    return image;
}

Use the image to set the image property of your UIImageView and set the contentMode property to UIViewContentModeScaleToFill.

like image 4
Robin Summerhill Avatar answered Nov 10 '22 03:11

Robin Summerhill