4

I know how clipsToBounds works. Or... at least, I thought I did.

Given the following Swift code:

class ViewController: UIViewController {
    @IBOutlet weak var redView: UIView!
    @IBOutlet weak var blueView: UIView!

    override func viewDidLoad() {
        super.viewDidLoad()
        self.redView.clipsToBounds = false
        self.blueView.clipsToBounds = true
    }
}

I get the following results:

Swift Clips To Bounds

(with apologies to anyone who is color blind, the top box is red, the bottom box is blue... they are hooked up correctly in interface builder)

Meanwhile, given the following, very equivalent, Objective-C code:

@interface ObjcController()

@property (weak, nonatomic) IBOutlet UIView *redView;
@property (weak, nonatomic) IBOutlet UIView *blueView;

@end

@implementation ObjcController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.redView.clipsToBounds = NO;
    self.blueView.clipsToBounds = YES;
}

@end

I get the following, very opposite, results:

ObjC Clips To Bounds

(with the same apologies to anyone who is colorblind, once again, the top box is red, the bottom box is blue, and they're still hooked up in the same way as the Swift implementation was hooked up)

Am I overlooking something very obvious? Or is this a Swift bug? I'm using the same IB file and just changing the view controller's class (and hooking the buttons back up).

For verification that I hooked up the views correctly:

Swift Red View Swift Blue View ObjC Red View ObjC Blue View

Community
  • 1
  • 1
nhgrif
  • 61,578
  • 25
  • 134
  • 173
  • My guess: Try setting `clipsToBounds` before you perform any drawing actions on the views? – Dair Mar 04 '15 at 23:01
  • I'm not performing any drawing actions? – nhgrif Mar 04 '15 at 23:11
  • Nvm. I thought that maybe the order might matter... Guess not then... – Dair Mar 05 '15 at 00:22
  • 1
    I've just tested.... the result in Swift is the same with Obj-C (Xcode 6.1) - here is the test https://dl.dropboxusercontent.com/u/19438780/testClipsToBounds.zip – TonyMkenu Mar 05 '15 at 10:46
  • @TonyMkenu I've just loaded your project on my machine. Your project behaves as I would expect, but my project is still behaving as outlined in the question above. Any *clue* where to begin searching for what the difference might be? – nhgrif Mar 07 '15 at 13:56
  • Which Xcode version are you using? On Xcode 6.3 beta 3 it's working properly. – Aleksi Sjöberg Mar 18 '15 at 14:42
  • @alkku When I originally posted this problem, I was on Xcode 6.1 (6.2 was in beta). I've since upgraded to 6.2 and the problem persists in this project. – nhgrif Mar 29 '15 at 01:35
  • @nhgrif, seems this problem is resolved in XCode 6.3, right? http://i.imgur.com/rguy6P5.png – ztan Apr 17 '15 at 22:58
  • 7
    I know you've said your outlets are hooked up correctly, but that honestly looks like the most likely candidate. Maybe try removing them, then re-hooking them up? – dalton_c Jul 09 '15 at 22:52
  • 1
    I eould really try to re-create connections :) It's mot about the swift. It's about XIB loading mechanism. Swift compiler will not confuse two outlets. Or, well... it can. But the probability is just very low. I'd perhaps try to read the xib/storyboard file in emacs (or vi!) and check what's there. – simpleone Sep 30 '15 at 22:13
  • Maybe the Xcode "bug", have you tried to recreate a swift project and test? – ZYiOS Dec 15 '15 at 08:03

0 Answers0