Is it possible to add a border style to a UITableView?
Not just bordercolor and borderwidth.
For example a grooved border style?
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.
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.....
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With