StalinPusparaj
StalinPusparaj

Reputation: 53

How to set smooth border color on UIView?

i have added a UIView on the View Controller.Initially i set the border color on the UIView now it looks view border smoothly.But while scaling that View through Gesture recognizer the border color would be pixelated .

initial code below here

- (id)initWithImage:(UIImage*)image delegate:(id)delegat{
    if ( (self = [super initWithImage:image]) ) {
        self.layer.masksToBounds = YES;
        self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width+1, self.frame.size.height+1);
        self.contentMode = UIViewContentModeCenter;
        ratio = image.size.height / image.size.width;
        itemType = 2;
        self.userInteractionEnabled =TRUE;
        self.delegate = delegat;
        self.layer.borderColor = [UIColor redColor].CGColor;
        self.layer.borderWidth = 4;
        scaleFactor = 1.0;
        rotateAngle = 0.0;
        fontSize = 22;
        self.contentScaleFactor = 1.0;
        if(image != nil){
            frameWidth = image.size.width;
            frameHeight = image.size.height;
        }else{
            frameWidth = self.frame.size.width;
            frameHeight = self.frame.size.height;    
        }

        [self addGestureRecognizers];
    }    
    return self;
}

enter image description here

here is code for rotate code

- (void)rotatePiece:(UIRotationGestureRecognizer *)gestureRecognizer{


    if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] == UIGestureRecognizerStateChanged) {
        // To undo the action : store information
        [[UIAppDelegate viewController] storeAction:CHUndoActionTypeRotate item:self];

        [gestureRecognizer view].transform = CGAffineTransformRotate([[gestureRecognizer view] transform], [gestureRecognizer rotation]);
        [gestureRecognizer setRotation:0];
    }

}

this is what i got while rotate the view

enter image description here

Upvotes: 1

Views: 3377

Answers (1)

Dima
Dima

Reputation: 23634

This is a seemingly pretty common issue. What you want is for the borders to be anti-aliased. Here is one post with a solution and here is another.

Basically you could use a UIImageView and add a one pixel transparent border around the image, so that the actual border would be anti-aliased.

Upvotes: 1

Related Questions