Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Blakeasd

macrumors 6502a
Original poster
Dec 29, 2009
643
0
Hello,

I am working on a window that is a subclass of the INAppStoreWindow. I am attempting to add an NSTextField to the window, which I have done, but there are some "fine tuning" issues. The INAppStoreWindow is a window that lets you get its "titlebarview" and add stuff to it. I have added a textfield to it like this:

Code:
 [_window setTitleBarHeight:60.0]; //1
    
    NSView *titleBarView = self.window.titleBarView; //2

    newTitleView.bounds.size.width = titleBarView.bounds.size.width; //3
    
    
    [titleBarView addSubview:newTitleView]; //4

The newTitleView is an IBOutlet in Interface Builder (a view with the textfield in it), and the _window is just my standard INAppStoreWindow. The view has the textfield perfectly aligned in it and displays fine in the window's titlebar. The issue is resizing. The textfield won't resize when the window resizes. I though that to fix this I should make the newTitleView change in width with the titleBarView, so I added line 3 above. I get an error though when I try to run it, stating: "The Expression is not assignable." So how can I make it "Assignable". And if I do succeed, will the textfield resize?

Thanks!
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,560
6,059
This was answered on StackOverflow over here... I provided what, in my opinion, was a pretty good solution for how you can do what you want:

http://stackoverflow.com/questions/9537573/ios-frame-change-one-property-eg-width/14116702#14116702

The answer why this isn't possible is because when you type out newTitleView.bounds on the left side of an assignment, it compiles to this:

Code:
[newTitleView setBounds:[titleBarView getBounds].size.width];

Except that doesn't work, because setBounds: expects a CGRect, not a CGFloat.

Something you may or may not realize is this: bounds is a property of views, but size is a member of struct CGRect and width is a member of struct CGSize... size and width are not properties. If you don't understand that, you might be in need of refreshing yourself on C structs.
 
Last edited:

ytk

macrumors 6502
Jul 8, 2010
252
5
I'm going to offer you my totally half-assed, uninformed, all-but-worthless answer here, and say that in Cocoa the only appropriate way to set the size of the bounds of an NSView is with the view's setBounds: or setBoundsSize: methods. I don't think there's any way to set only the width directly, but since an NSSize is just a struct containing two floats, you should be able to build the struct on the fly by combining titleBarView.bounds.size.width and newTitleView.bounds.size.height, and then pass the resultant struct to [newTitleView setBoundsSize:]. I'm drawing a blank on the exact syntax for doing this in Objective-C at the moment, but I'm pretty sure it's possible.

Of course, I could be completely wrong, and you should probably disregard everything I've written here. :D
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.