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

后端 未结 5 662
逝去的感伤
逝去的感伤 2020-12-29 15:40

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

Not just bordercolor and borderwidth.

For example a grooved border style?

相关标签:
5条回答
  • 2020-12-29 15:57

    You can't set the style, but you can simulate a pattern like a dotted line by using a pattern image and a UIColor.

    UIView *item;
    item.layer.borderColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"checkerboard.png"]].CGColor;
    

    Don't forget to add this to your headers:

    #import <QuartzCore/QuartzCore.h>
    
    0 讨论(0)
  • 2020-12-29 16:01

    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.

    0 讨论(0)
  • 2020-12-29 16:03

    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.

    0 讨论(0)
  • 2020-12-29 16:03

    What you can do is Get the Image of the Texture and Put that Image in UIImageView and then add TableView in the Imageview like it shows the Image from all sides...

    0 讨论(0)
  • 2020-12-29 16:08

    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.....

    0 讨论(0)
提交回复
热议问题