Custom Button frame doesn't look as good as Round Rect UIButton

后端 未结 2 850
没有蜡笔的小新
没有蜡笔的小新 2021-01-11 18:32

I\'m trying to draw a custom button frame as follows:

UIBezierPath *stroke = [UIBezierPath bezierPathWithRoundedRect:self.bounds
                                     


        
2条回答
  •  青春惊慌失措
    2021-01-11 19:19

    The problem you have is probably due to antialiasing. You can try to change the antialiasing settings of CoreGraphics before drawing your beizerPath.

    An easier solution is to use the CALayer of your button and its cornerRadius property. It would be easier to draw a rounded corner

    If self is your custom button:

    self.layer.cornerRadius = RECT_CORNER_RADIUS;
    self.layer.borderWidth = 1.0f;
    self.layer.borderColor = [UIColor blackColor].CGColor;
    

    Of course don't forget to import the QuartzCore framework and import its header for this to work (#import )

提交回复
热议问题