Date   

More Layout Questions

Dave
 

Hi,

I have a couple of questions related to manual layout on the Mac.

Using manual layout, does setting the “frame: of a view cause “layout” to be called or do I need to call “setNeedsLayout” specifically?


In general, is there a particular way in which the NSView “layout” method is supposed to work or is it up to the developer to choose?


From the docs:

Override this method if your custom view needs to perform custom layout not expressible using the constraint-based layout system. In this case you are responsible for setting needsLayout to YES when something that impacts your custom layout changes.

You may not invalidate any constraints as part of your layout phase, nor invalidate the layout of your superview or views outside of your view hierarchy. You also may not invoke a drawing pass as part of layout.

You must call [super layout] as part of your implementation.

Should the “layout” method change the value of their “frame” property or should this be done by the superview?

I have a View Hierarchy and when the window resizes, I change the sizes and positions of the views within each subview. It seem to me that there are two ways of doing it given the following Hierarchy:

WindowTrackingView (.view)
LeftAreaView
ContainerViewA

RightAreaView
ContainerViewB

So, when the window resized, WindowTrackingView::layout gets called with its “frame” property set to the new size. 

At this point there are two options:

1. WindowTrackingView::layout simply calls “setNeedsLayout” for each of its subviews and each subview sets their own frame based on the “frame" rectangle of the superview via their own “layout” method.

2.  WindowTrackingView::layout calculates and sets the frame of each of its subviews based on its own “frame” in this case and then calls “setNeedsDisplay” (unless this is already done if the “frame” changes?).

Is any of these methods preferred or is it up to the developer to choose based on the job in hand?


Any help on this greatly appreciated, I’ve written a test app and have almost got my head around manual layout, I just need to understand if this last bit.

Thanks in advance.

All the Best
Dave
















Re: Updating to Xcode 10

John Brownie
 

Oh boy. I am only targeting macOS (10.9 for this release), so it should still be doable. This will be a stop-gap while I work on the migration of the whole code base to Swift. I'm relying on a third-party base, Nano, which is coded with the GNU stdlib in mind, and that's one more reason to move to Swift.

In the meantime, is it going to be possible to add a version of libstdc++ to Xcode? Given code signing and all that, I guess it wouldn't be possible to stick it into the SDK, so it would have to be /usr/include or /usr/local/include. Is the best way to go through the whole gcc installation, or is there a shortcut I can make?

Thanks for pointing out the release notes. Life is too short to read everything when trying to catch up after several months away from the project!

John

Jack Brindle via Groups.Io wrote on 21/9/18 15:22:

John;

It’s usually a good thing to read the release notes for each version of Xcode. The Xcode 10 release notes directly mention the issue you are facing:

Building with libstdc++ was deprecated with Xcode 8 and is not supported in Xcode 10 when targeting iOS. C++ projects must now migrate to libc++ and are recommended to set a deployment target of macOS 10.9 or later, or iOS 7 or later. Besides changing the C++ Standard Library build setting, developers should audit hard-coded linker flags and target dependencies to remove references to libstdc++ (including -lstdc++, -lstdc++.6.0.9, libstdc++.6.0.9.tbd, and libstdc++.6.0.9.dylib). Project dependencies such as static archives that were built against libstdc++ will also need to be rebuilt against libc++. (40885260)

Libgcc is obsoleted. Xcode 10 can no longer build apps with deployment targets of macOS 10.4 and 10.5. (42818150, 38035243) 


It looks like they really want you to change libraries to use libc++.

Jack


On Sep 21, 2018, at 3:33 AM, John Brownie <john_brownie@...> wrote:

I discovered one thing that is a bug in Xcode. In the section Apple Clang - Language - C++, if you set the C++ Standard Library to the option libstdc++ (GNU C++ Standard Library), it generates the -std=libstdc++. When it fails to find it, it generates the erroneous warning.

Anyway, it looks as though the issue is that the C++ library that I rely on is built with the GNU C++ Standard Library in mind, and that is not present on my machine. I assume that it disappeared at some point in the past, possibly between Xcode 9.2 (which was the last version I was using) and Xcode 10.0. Is there a way to get it back?

John

Alex Zavatone via Groups.Io wrote on 20/9/18 21:24:
Did you change your linked library to the new C++ one?

On Sep 20, 2018, at 2:32 AM, John Brownie <john_brownie@...> wrote:

After a hiatus of some months, I'm back to programming, and just got Xcode 10 installed. When I go to build, I get all kinds of changes suggested. I make some, but then I get stuck some that I cannot work out. My project is a mixture of Objective-C, Objective-C++, C++, and a little Swift (in a separate target).

When I start to build the first target, clang gives the the warning:
warning: include path for stdlibc++ headers not found; pass '-std=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]

OK, so I add a compiler flag as suggested, and I get the following warnings:
error: invalid value 'libc++' in '-std=libc++'
note: use 'c++98' or 'c++03' for 'ISO C++ 1998 with amendments' standard
note: use 'gnu++98' or 'gnu++03' for 'ISO C++ 1998 with amendments and GNU extensions' standard
note: use 'c++11' for 'ISO C++ 2011 with amendments' standard
note: use 'gnu++11' for 'ISO C++ 2011 with amendments and GNU extensions' standard
note: use 'c++14' for 'ISO C++ 2014 with amendments' standard
note: use 'gnu++14' for 'ISO C++ 2014 with amendments and GNU extensions' standard
note: use 'c++17' for 'ISO C++ 2017 with amendments' standard
note: use 'gnu++17' for 'ISO C++ 2017 with amendments and GNU extensions' standard
note: use 'c++2a' for 'Working draft for ISO C++ 2020' standard
note: use 'gnu++2a' for 'Working draft for ISO C++ 2020 with GNU extensions' standard

Using one of those (c++11), brings me back to the first warning. And then the compiler can't find the standard library headers (e.g. <algorithm>), anyway.

One of the suggested changes was "Update C++ Standard Library", so I reverted to pre-changes and didn't make that change, which got me to the second set of warnings.

Anyone have an idea how to break out of this cycle?

John
--
John Brownie
Mussau-Emira language, New Ireland Province, Papua New Guinea
Kouvola, Finland






--
John Brownie
Mussau-Emira language, New Ireland Province, Papua New Guinea
Kouvola, Finland





--
John Brownie
Mussau-Emira language, New Ireland Province, Papua New Guinea
Kouvola, Finland


Re: Updating to Xcode 10

Jack Brindle
 

John;

It’s usually a good thing to read the release notes for each version of Xcode. The Xcode 10 release notes directly mention the issue you are facing:

Building with libstdc++ was deprecated with Xcode 8 and is not supported in Xcode 10 when targeting iOS. C++ projects must now migrate to libc++ and are recommended to set a deployment target of macOS 10.9 or later, or iOS 7 or later. Besides changing the C++ Standard Library build setting, developers should audit hard-coded linker flags and target dependencies to remove references to libstdc++ (including -lstdc++, -lstdc++.6.0.9, libstdc++.6.0.9.tbd, and libstdc++.6.0.9.dylib). Project dependencies such as static archives that were built against libstdc++ will also need to be rebuilt against libc++. (40885260)

Libgcc is obsoleted. Xcode 10 can no longer build apps with deployment targets of macOS 10.4 and 10.5. (42818150, 38035243) 


It looks like they really want you to change libraries to use libc++.

Jack


On Sep 21, 2018, at 3:33 AM, John Brownie <john_brownie@...> wrote:

I discovered one thing that is a bug in Xcode. In the section Apple Clang - Language - C++, if you set the C++ Standard Library to the option libstdc++ (GNU C++ Standard Library), it generates the -std=libstdc++. When it fails to find it, it generates the erroneous warning.

Anyway, it looks as though the issue is that the C++ library that I rely on is built with the GNU C++ Standard Library in mind, and that is not present on my machine. I assume that it disappeared at some point in the past, possibly between Xcode 9.2 (which was the last version I was using) and Xcode 10.0. Is there a way to get it back?

John

Alex Zavatone via Groups.Io wrote on 20/9/18 21:24:
Did you change your linked library to the new C++ one?

On Sep 20, 2018, at 2:32 AM, John Brownie <john_brownie@...> wrote:

After a hiatus of some months, I'm back to programming, and just got Xcode 10 installed. When I go to build, I get all kinds of changes suggested. I make some, but then I get stuck some that I cannot work out. My project is a mixture of Objective-C, Objective-C++, C++, and a little Swift (in a separate target).

When I start to build the first target, clang gives the the warning:
warning: include path for stdlibc++ headers not found; pass '-std=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]

OK, so I add a compiler flag as suggested, and I get the following warnings:
error: invalid value 'libc++' in '-std=libc++'
note: use 'c++98' or 'c++03' for 'ISO C++ 1998 with amendments' standard
note: use 'gnu++98' or 'gnu++03' for 'ISO C++ 1998 with amendments and GNU extensions' standard
note: use 'c++11' for 'ISO C++ 2011 with amendments' standard
note: use 'gnu++11' for 'ISO C++ 2011 with amendments and GNU extensions' standard
note: use 'c++14' for 'ISO C++ 2014 with amendments' standard
note: use 'gnu++14' for 'ISO C++ 2014 with amendments and GNU extensions' standard
note: use 'c++17' for 'ISO C++ 2017 with amendments' standard
note: use 'gnu++17' for 'ISO C++ 2017 with amendments and GNU extensions' standard
note: use 'c++2a' for 'Working draft for ISO C++ 2020' standard
note: use 'gnu++2a' for 'Working draft for ISO C++ 2020 with GNU extensions' standard

Using one of those (c++11), brings me back to the first warning. And then the compiler can't find the standard library headers (e.g. <algorithm>), anyway.

One of the suggested changes was "Update C++ Standard Library", so I reverted to pre-changes and didn't make that change, which got me to the second set of warnings.

Anyone have an idea how to break out of this cycle?

John
--
John Brownie
Mussau-Emira language, New Ireland Province, Papua New Guinea
Kouvola, Finland






--
John Brownie
Mussau-Emira language, New Ireland Province, Papua New Guinea
Kouvola, Finland





How to end a UIKeyboardTypeDecimalPad

Gerriet M. Denkmann
 

I got a UITextField which has a UIKeyboardTypeDecimalPad.

With a normal TextField (UIKeyboardTypeDefault) the user can enter Return, the UITextFieldDelegate gets textFieldShouldReturn and all is well.

But how should the user tell the app that enough digits have been entered, as the DecimalPad has no Return key?


Gerriet.


Re: Updating to Xcode 10

John Brownie
 

I discovered one thing that is a bug in Xcode. In the section Apple Clang - Language - C++, if you set the C++ Standard Library to the option libstdc++ (GNU C++ Standard Library), it generates the -std=libstdc++. When it fails to find it, it generates the erroneous warning.

Anyway, it looks as though the issue is that the C++ library that I rely on is built with the GNU C++ Standard Library in mind, and that is not present on my machine. I assume that it disappeared at some point in the past, possibly between Xcode 9.2 (which was the last version I was using) and Xcode 10.0. Is there a way to get it back?

John

Alex Zavatone via Groups.Io wrote on 20/9/18 21:24:

Did you change your linked library to the new C++ one?

On Sep 20, 2018, at 2:32 AM, John Brownie <john_brownie@sil.org> wrote:

After a hiatus of some months, I'm back to programming, and just got Xcode 10 installed. When I go to build, I get all kinds of changes suggested. I make some, but then I get stuck some that I cannot work out. My project is a mixture of Objective-C, Objective-C++, C++, and a little Swift (in a separate target).

When I start to build the first target, clang gives the the warning:
warning: include path for stdlibc++ headers not found; pass '-std=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]

OK, so I add a compiler flag as suggested, and I get the following warnings:
error: invalid value 'libc++' in '-std=libc++'
note: use 'c++98' or 'c++03' for 'ISO C++ 1998 with amendments' standard
note: use 'gnu++98' or 'gnu++03' for 'ISO C++ 1998 with amendments and GNU extensions' standard
note: use 'c++11' for 'ISO C++ 2011 with amendments' standard
note: use 'gnu++11' for 'ISO C++ 2011 with amendments and GNU extensions' standard
note: use 'c++14' for 'ISO C++ 2014 with amendments' standard
note: use 'gnu++14' for 'ISO C++ 2014 with amendments and GNU extensions' standard
note: use 'c++17' for 'ISO C++ 2017 with amendments' standard
note: use 'gnu++17' for 'ISO C++ 2017 with amendments and GNU extensions' standard
note: use 'c++2a' for 'Working draft for ISO C++ 2020' standard
note: use 'gnu++2a' for 'Working draft for ISO C++ 2020 with GNU extensions' standard

Using one of those (c++11), brings me back to the first warning. And then the compiler can't find the standard library headers (e.g. <algorithm>), anyway.

One of the suggested changes was "Update C++ Standard Library", so I reverted to pre-changes and didn't make that change, which got me to the second set of warnings.

Anyone have an idea how to break out of this cycle?

John
--
John Brownie
Mussau-Emira language, New Ireland Province, Papua New Guinea
Kouvola, Finland


--
John Brownie
Mussau-Emira language, New Ireland Province, Papua New Guinea
Kouvola, Finland


Re: Segue

Quincey Morris
 

On Sep 20, 2018, at 22:50 , Gerriet M. Denkmann <g@...> wrote:

This is probably self-evident (and probably also well documented),

It is self-evident after you read the documentation, but it takes about a day to read the documentation …

but it took me more than a day to figure this out.

… and if you’d spent the day reading the documentation, it wouldn’t have taken a day to figure out. ;)

TBH, it’s a bit frightening how abstruse the controller interactions have become on iOS over the years. If you study the master-detail app template in Xcode, you’ll see that it gives the iPad *both* a split view controller *and* a navigation controller, and it switches between the two dynamically, depending on how the split view interacts with a compact dimension.

If you want to make your head hurt, you can spend another day figuring out how the machinery in the App Delegate and the MasterViewController, and the cross-linked navigation controllers in the storyboard all work together to do some very clever things. I particular like this comment in the helper method near the end of the App Delegate:

            // Return true to indicate that we have handled the collapse by doing nothing; the secondary controller will be discarded.

This is quite a strange rabbit hole to disappear into.


Re: Segue

Gerriet M. Denkmann
 

On 20 Sep 2018, at 22:19, Rick Aurbach via Groups.Io <rlaurb=me.com@groups.io> wrote:

I'm not sure I am understanding your problem correctly, but I am wondering about the exact layout of your storyboard. Specifically, are you using a UISplitViewController? The Push (Detail) segue is specific to it.

On an iPhone (particularly in portrait mode), the push-detail segue looks like a simple push, but it is not. You can see this when running on an iPad in Simulator, where you will see both the TableViewController and the Detail controller (in whole or with part of it covered by the TableViewController) side by side. The push detail segue brings the detail controller to the front, covering (hiding) the TableViewController. On a phone, this just looks like a push.

If you don't have a split-view controller, then the segue can't do that (i.e., it can't call UISplitViewController.showDetailViewController) and is apparently doing a simple UIViewController.present instead.

If I’m off on a mistaken tangent here, please excuse the waste of bandwidth.
You are quite right. The Xcode template “Master-Detail App” uses a SplitViewController, and it works fine.
And it works for both iPad and iPhone.

But you can do (iPhone only ?) without a SplitViewController as well:

UINavigationController → UIViewController (Master) → UIViewController (Detail) works as expected.

Three important points:
1. The Master *must* be preceded by an UINavigationController
2. There must be *no* UINavigationController between Master and Detail.
3. The Segue Master to Detail *must* be of Kind: Show (e.g. Push)

This is probably self-evident (and probably also well documented), but it took me more than a day to figure this out.

Kind regards,

Gerriet.


Re: Can NSView and NSImageView respond to Mouse Clicks?

Jack Brindle
 

NSView inherits from NSResponder. That gives NSView access to mouseDown, mouseUp and a whole host of other important calls.
What this really means is that you can implement
- (void)mouseDown:(NSEvent *)event;
or
v- (void) mouseUp:(NSEvent *)event;
in your NSView subclass and handle mouse events the way you like, which includes generating IBAction calls to other objects that need to be notified of mouse events in your view.
The event object will contains information about where the cursor was when the mouse down or up even occurred, which you can use to determine exactly where in the view the hit occurred, and even when.
Note that any control embedded in the view will take precedence over the view itself, so that it gets a chance to handle the mouse down first.

After all these years, I still find it really cool the way events and the responder chain works, and gives us so much power to create great user interfaces.

Jack

On Sep 20, 2018, at 4:36 AM, Dave <dave@looktowindward.com> wrote:

Hi,

This is for NSView, I’ve not looked into NSImageView as yet.

I tried adding a Gesture Recognizer which sort of work except the Handler gets calls more than nice when I mouse down.

Basically, I want to detect a Mouse Down on an NSView Subclass and when it occurs display a Pop-Up Menu. Don’t understand why I'm getting multiple calls - see code below.

All the Best
Dave

-(instancetype) initWithCoder:(NSCoder*) theDecoder
{
self = [super initWithCoder:theDecoder];
if (self == nil)
return nil;

NSLog(@"initWithCoder: %@",self.identifier);
[self setupView];

return self;
}


-(void) setupView
{
NSPressGestureRecognizer* myGestureRecognizer;

myGestureRecognizer = [[NSPressGestureRecognizer alloc] initWithTarget:self action:@selector(actionPressGesture:)];
myGestureRecognizer.minimumPressDuration = 0.001;
myGestureRecognizer.buttonMask = 1;
myGestureRecognizer.delaysPrimaryMouseButtonEvents = NO;
[self addGestureRecognizer:myGestureRecognizer];
}

-(void) actionPressGesture:(LTWTestViewCell*) theSender
{
NSLog(@"actionPressGesture: %@",self.identifier);
}


On 20 Sep 2018, at 02:03, Alex Zavatone via Groups.Io <zav=mac.com@groups.io> wrote:

You can add a gesture to it IIRC.
On Sep 19, 2018, at 1:34 PM, Dave <dave@looktowindward.com> wrote:

Hi,

Can an Custom NSView respond to Mouse Clicks via IBActions?

Can the same be done with NSImageView? I’ve added an image view and connected it to an IBAction method define in my View Controller, but when I click the NSImageView nothing happens…..

Any help greatly appreciated.

All the Best
Dave





Re: Can NSView and NSImageView respond to Mouse Clicks?

Sean McBride
 

On Thu, 20 Sep 2018 11:36:10 +0200, Dave said:

Basically, I want to detect a Mouse Down on an NSView Subclass and when
it occurs display a Pop-Up Menu.
Suggestion: open NSView.h and search for "menu", there are API like menuForEvent: and willOpenMenu: that look useful for your case.

Cheers,

Sean


Re: Updating to Xcode 10

Alex Zavatone
 

Did you change your linked library to the new C++ one?

On Sep 20, 2018, at 2:32 AM, John Brownie <john_brownie@sil.org> wrote:

After a hiatus of some months, I'm back to programming, and just got Xcode 10 installed. When I go to build, I get all kinds of changes suggested. I make some, but then I get stuck some that I cannot work out. My project is a mixture of Objective-C, Objective-C++, C++, and a little Swift (in a separate target).

When I start to build the first target, clang gives the the warning:
warning: include path for stdlibc++ headers not found; pass '-std=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]

OK, so I add a compiler flag as suggested, and I get the following warnings:
error: invalid value 'libc++' in '-std=libc++'
note: use 'c++98' or 'c++03' for 'ISO C++ 1998 with amendments' standard
note: use 'gnu++98' or 'gnu++03' for 'ISO C++ 1998 with amendments and GNU extensions' standard
note: use 'c++11' for 'ISO C++ 2011 with amendments' standard
note: use 'gnu++11' for 'ISO C++ 2011 with amendments and GNU extensions' standard
note: use 'c++14' for 'ISO C++ 2014 with amendments' standard
note: use 'gnu++14' for 'ISO C++ 2014 with amendments and GNU extensions' standard
note: use 'c++17' for 'ISO C++ 2017 with amendments' standard
note: use 'gnu++17' for 'ISO C++ 2017 with amendments and GNU extensions' standard
note: use 'c++2a' for 'Working draft for ISO C++ 2020' standard
note: use 'gnu++2a' for 'Working draft for ISO C++ 2020 with GNU extensions' standard

Using one of those (c++11), brings me back to the first warning. And then the compiler can't find the standard library headers (e.g. <algorithm>), anyway.

One of the suggested changes was "Update C++ Standard Library", so I reverted to pre-changes and didn't make that change, which got me to the second set of warnings.

Anyone have an idea how to break out of this cycle?

John
--
John Brownie
Mussau-Emira language, New Ireland Province, Papua New Guinea
Kouvola, Finland



Re: Adjusting Font Size to fit View Rectangle

Ben Kennedy
 

On 20 Sep 2018, at 2:51 am, Dave <dave@looktowindward.com> wrote:

Those two methods alter the frame size, I want to keep the same Frame Size but reduce the Font Size of the Content until it fit into the Displayable Area. I’m 99% sure there is a method to do it but maybe its iOS only?
UILabel has `adjustsFontSizeToFitWidth` and `minimumScaleFactor` properties that aim to support that type of thing automatically. Could you employ it?

b


Re: Updating to Xcode 10

 



On Sep 20, 2018, at 12:32 AM, John Brownie <john_brownie@...> wrote:

When I start to build the first target, clang gives the the warning:
warning: include path for stdlibc++ headers not found; pass '-std=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]

I build a lot of C++ and I don’t think I’ve ever seen that. Are you overriding the header search path or specifying any exotic compiler flags already? And double-check that you’ve got a valid SDK selected.

‘-std=libc++’ seems fishy to me, since the value of -std is supposed to be a language version like “c++11”.

—Jens


Re: Adjusting Font Size to fit View Rectangle

Alex Zavatone
 

You also might want to check the height of a descender appears below the bounding NSTextField.

On Sep 20, 2018, at 5:21 AM, Dave <dave@looktowindward.com> wrote:

Hi,

Couldn’t find it so wrote my own:

(NSInteger) adjustFontSize:(NSInteger) theFontSize toFitWidth:(NSInteger) theWidth
{
NSInteger myFontSize;
NSFont* myFont;
NSSize myContentSize;

myFontSize = theFontSize;
while (YES)
{
myFont = [NSFont fontWithName:self.font.fontName size:myFontSize];
[self setFont:myFont];

myContentSize = [self.attributedStringValue size];
if (myContentSize.width < theWidth)
break;

myFontSize--;
if (myFontSize <= 0)
break;
}

return myFontSize;
}

This is on an NSTextField subclass and works a treat!

All the Best
Dave

On 20 Sep 2018, at 11:51, Dave <dave@looktowindward.com> wrote:

Hi,

Those two methods alter the frame size, I want to keep the same Frame Size but reduce the Font Size of the Content until it fit into the Displayable Area. I’m 99% sure there is a method to do it but maybe its iOS only?

All the Best
Dave

On 20 Sep 2018, at 02:02, Alex Zavatone via Groups.Io <zav=mac.com@groups.io> wrote:

There are two that I am aware of. sizeToFit and sizeThatFits.
On Sep 19, 2018, at 1:29 PM, Dave <dave@looktowindward.com> wrote:

Hi All,

Is there a Cocoa method I can use that will return the best fitting Font Size for a given String and Font?

I seem to remember using a method that does it but can’t seem to find it any more…..

All the Best
Dave








Re: Segue

Rick Aurbach
 

I'm not sure I am understanding your problem correctly, but I am wondering about the exact layout of your storyboard. Specifically, are you using a UISplitViewController? The Push (Detail) segue is specific to it. 

On an iPhone (particularly in portrait mode), the push-detail segue looks like a simple push, but it is not. You can see this when running on an iPad in Simulator, where you will see both the TableViewController and the Detail controller (in whole or with part of it covered by the TableViewController) side by side. The push detail segue brings the detail controller to the front, covering (hiding) the TableViewController. On a phone, this just looks like a push.

If you don't have a split-view controller, then the segue can't do that (i.e., it can't call UISplitViewController.showDetailViewController) and is apparently doing a simple UIViewController.present instead.

If I'm off on a mistaken tangent here, please excuse the waste of bandwidth.

Rick Aurbach


Re: Adjusting Font Size to fit View Rectangle

Sandor Szatmari
 

Yes, I’m sure single line (text field) instead of multiline (text view) can be accomplished with less rigor.  Let me know if you find anything interesting.

Sandor

On Sep 20, 2018, at 09:12, Dave <dave@...> wrote:

Hi,

I think it should work ok on iOS, will find out soon, there maybe some differences in method names etc.

I should have been more clear, this is for a single line, it should work for multiple lines too, but probably not as well as your suggestion, which is overkill for what I want it for.

All the Best
Dave

On 20 Sep 2018, at 15:00, Sandor Szatmari <admin.szatmari.net@...> wrote:

This was for macOS…  not sure how to go about it on iOS.  I’d guess it would work, but there may be an easier method.  I don’t know though.

I have used this method to dynamically size formatted multiline text (text that includes line breaks) to find the maximum font size for a fixed container size.  Granted there may be an easier solution that I am not aware of, but I am also counting the number of line of text being laid out, so this solution works for me.

1. Get text
2. Setup your mutable paragraph style, set properties, justification, wrapping… etc.
3. Create a layout manager… set properties, hyphenation, etc.  Important, set the layout mgr’s delegate (I used self for simplicity). You will receive callbacks about the layout process via delegation.
3a. Define delegate method -layoutManager:didCompleteLayoutForTextContainer:atEnd: (you will receive these callbacks where you can flag ‘clipping’ I.e. text too big) set a flag here indicating clipping has occurred.  I used an iVar.
4. Create a mutable attributes dict, this contains the para style keyed on NSParagraphStyleAttributeName.  (You will add/update the font later stored in this dict with different sizes later)
5. Create a text storage object with text and para style
6. Now loop… do while (notClipped && other things you care about)
Loop Body
a. Adjust font size
b. Create new NSFont object with new size.  Set font in attributes dict keyed on NSFontAttributeName
c. Adjust paragraph style as needed/desired (optional)
d. Reapply (Set) the updated attributes dict for the entire range of text in your text storage object -setAtteibutes:range:
e. Ask the layout manager/text storage to layout the text.  If the text is too big the container parameter in your callback will be nil indicating that ‘clipping’ occurred.  Use nil container to flag clipping thus communicating with your loop.

Rinse, repeat… till desired font size reached


The text generated using this approach is displayed in widgets that are part of a complex visual graph of objects all of which are the same size and which contain dynamic multiline text.   I have additional logic that counts the number of lines to ensure that there are always three lines.  Each line contains a different property of the object being represented.  IP, hostname, etc…  Think graphical displays of networks and such, with text inside the network components.

Sandor

On Sep 20, 2018, at 05:51, Dave <dave@...> wrote:

Hi,

Those two methods alter the frame size, I want to keep the same Frame Size but reduce the Font Size of the Content until it fit into the Displayable Area. I’m 99% sure there is a method to do it but maybe its iOS only?

All the Best
Dave

On 20 Sep 2018, at 02:02, Alex Zavatone via Groups.Io <zav@...> wrote:

There are two that I am aware of.  sizeToFit and sizeThatFits.
On Sep 19, 2018, at 1:29 PM, Dave <dave@...> wrote:

Hi All,

Is there a Cocoa method I can use that will return the best fitting Font Size for a given String and Font?

I seem to remember using a method that does it but can’t seem to find it any more…..

All the Best
Dave







Re: Adjusting Font Size to fit View Rectangle

Alex Zavatone
 

I do think that based on your requirements, there will have been others who have solved this. I just found a few solutions on Stack Overflow that could be adopted to MacOS.

Will send off list.

On Sep 20, 2018, at 4:51 AM, Dave <dave@looktowindward.com> wrote:

Hi,

Those two methods alter the frame size, I want to keep the same Frame Size but reduce the Font Size of the Content until it fit into the Displayable Area. I’m 99% sure there is a method to do it but maybe its iOS only?

All the Best
Dave

On 20 Sep 2018, at 02:02, Alex Zavatone via Groups.Io <zav=mac.com@groups.io> wrote:

There are two that I am aware of. sizeToFit and sizeThatFits.
On Sep 19, 2018, at 1:29 PM, Dave <dave@looktowindward.com> wrote:

Hi All,

Is there a Cocoa method I can use that will return the best fitting Font Size for a given String and Font?

I seem to remember using a method that does it but can’t seem to find it any more…..

All the Best
Dave







Re: Adjusting Font Size to fit View Rectangle

Dave
 

Hi,

I think it should work ok on iOS, will find out soon, there maybe some differences in method names etc.

I should have been more clear, this is for a single line, it should work for multiple lines too, but probably not as well as your suggestion, which is overkill for what I want it for.

All the Best
Dave

On 20 Sep 2018, at 15:00, Sandor Szatmari <admin.szatmari.net@...> wrote:

This was for macOS…  not sure how to go about it on iOS.  I’d guess it would work, but there may be an easier method.  I don’t know though.

I have used this method to dynamically size formatted multiline text (text that includes line breaks) to find the maximum font size for a fixed container size.  Granted there may be an easier solution that I am not aware of, but I am also counting the number of line of text being laid out, so this solution works for me.

1. Get text
2. Setup your mutable paragraph style, set properties, justification, wrapping… etc.
3. Create a layout manager… set properties, hyphenation, etc.  Important, set the layout mgr’s delegate (I used self for simplicity). You will receive callbacks about the layout process via delegation.
3a. Define delegate method -layoutManager:didCompleteLayoutForTextContainer:atEnd: (you will receive these callbacks where you can flag ‘clipping’ I.e. text too big) set a flag here indicating clipping has occurred.  I used an iVar.
4. Create a mutable attributes dict, this contains the para style keyed on NSParagraphStyleAttributeName.  (You will add/update the font later stored in this dict with different sizes later)
5. Create a text storage object with text and para style
6. Now loop… do while (notClipped && other things you care about)
Loop Body
a. Adjust font size
b. Create new NSFont object with new size.  Set font in attributes dict keyed on NSFontAttributeName
c. Adjust paragraph style as needed/desired (optional)
d. Reapply (Set) the updated attributes dict for the entire range of text in your text storage object -setAtteibutes:range:
e. Ask the layout manager/text storage to layout the text.  If the text is too big the container parameter in your callback will be nil indicating that ‘clipping’ occurred.  Use nil container to flag clipping thus communicating with your loop.

Rinse, repeat… till desired font size reached


The text generated using this approach is displayed in widgets that are part of a complex visual graph of objects all of which are the same size and which contain dynamic multiline text.   I have additional logic that counts the number of lines to ensure that there are always three lines.  Each line contains a different property of the object being represented.  IP, hostname, etc…  Think graphical displays of networks and such, with text inside the network components.

Sandor

On Sep 20, 2018, at 05:51, Dave <dave@...> wrote:

Hi,

Those two methods alter the frame size, I want to keep the same Frame Size but reduce the Font Size of the Content until it fit into the Displayable Area. I’m 99% sure there is a method to do it but maybe its iOS only?

All the Best
Dave

On 20 Sep 2018, at 02:02, Alex Zavatone via Groups.Io <zav@...> wrote:

There are two that I am aware of.  sizeToFit and sizeThatFits.
On Sep 19, 2018, at 1:29 PM, Dave <dave@...> wrote:

Hi All,

Is there a Cocoa method I can use that will return the best fitting Font Size for a given String and Font?

I seem to remember using a method that does it but can’t seem to find it any more…..

All the Best
Dave







Re: Adjusting Font Size to fit View Rectangle

Sandor Szatmari
 

This was for macOS… not sure how to go about it on iOS. I’d guess it would work, but there may be an easier method. I don’t know though.

I have used this method to dynamically size formatted multiline text (text that includes line breaks) to find the maximum font size for a fixed container size. Granted there may be an easier solution that I am not aware of, but I am also counting the number of line of text being laid out, so this solution works for me.

1. Get text
2. Setup your mutable paragraph style, set properties, justification, wrapping… etc.
3. Create a layout manager… set properties, hyphenation, etc. Important, set the layout mgr’s delegate (I used self for simplicity). You will receive callbacks about the layout process via delegation.
3a. Define delegate method -layoutManager:didCompleteLayoutForTextContainer:atEnd: (you will receive these callbacks where you can flag ‘clipping’ I.e. text too big) set a flag here indicating clipping has occurred. I used an iVar.
4. Create a mutable attributes dict, this contains the para style keyed on NSParagraphStyleAttributeName. (You will add/update the font later stored in this dict with different sizes later)
5. Create a text storage object with text and para style
6. Now loop… do while (notClipped && other things you care about)
Loop Body
a. Adjust font size
b. Create new NSFont object with new size. Set font in attributes dict keyed on NSFontAttributeName
c. Adjust paragraph style as needed/desired (optional)
d. Reapply (Set) the updated attributes dict for the entire range of text in your text storage object -setAtteibutes:range:
e. Ask the layout manager/text storage to layout the text. If the text is too big the container parameter in your callback will be nil indicating that ‘clipping’ occurred. Use nil container to flag clipping thus communicating with your loop.

Rinse, repeat… till desired font size reached


The text generated using this approach is displayed in widgets that are part of a complex visual graph of objects all of which are the same size and which contain dynamic multiline text. I have additional logic that counts the number of lines to ensure that there are always three lines. Each line contains a different property of the object being represented. IP, hostname, etc… Think graphical displays of networks and such, with text inside the network components.

Sandor

On Sep 20, 2018, at 05:51, Dave <dave@looktowindward.com> wrote:

Hi,

Those two methods alter the frame size, I want to keep the same Frame Size but reduce the Font Size of the Content until it fit into the Displayable Area. I’m 99% sure there is a method to do it but maybe its iOS only?

All the Best
Dave

On 20 Sep 2018, at 02:02, Alex Zavatone via Groups.Io <zav=mac.com@groups.io> wrote:

There are two that I am aware of. sizeToFit and sizeThatFits.
On Sep 19, 2018, at 1:29 PM, Dave <dave@looktowindward.com> wrote:

Hi All,

Is there a Cocoa method I can use that will return the best fitting Font Size for a given String and Font?

I seem to remember using a method that does it but can’t seem to find it any more…..

All the Best
Dave



Adding Action Methods to Controls

Dave
 

Ignore this, was a silly bug in that the identifier wasn’t setup correctly!


Adding Action Methods to Controls

Dave
 

Hi,

I’ve created an NSButton Class and added an Action to it as so:

myButton = [[NSButton alloc] initWithFrame:myButtonFrameRect];
myButton.image = myImage;
myButton.imageScaling = NSImageScaleProportionallyUpOrDown;
self.pCellButton = myButton;

self.pCellButton.target = self;
[self.pCellButton sendActionOn:NSEventMaskLeftMouseDown];
[self.pCellButton setAction:@selector(performCellSelected:)];

[self addSubview:self.pCellButton];



-(void) performCellSelected:(id) theSender
{
NSLog(@"performCellSelected: theSender: %@", theSender.identifier);
}

This works ok, EXCEPT the parameter pass in “theSender” is nil???? I would have thought it should be the NSButton object that the Action was sent from is this not the case?

All the Best
Dave

681 - 700 of 1422