I want Swift to omit the NavigationController title if there are more than a certain number of characters.

Asked 2 years ago, Updated 2 years ago, 48 views

The title displayed in the Navigation controller is
I am troubled that it looks like the attached image below.

What you want to do is to display
<Back, which is displayed by default on the Navigation Controller, on the far left. I want to display the title from the right side.
However, we are not able to do that now.
Is there a good way?

KVO monitors the title of WKWebView and
I want to insert the title of the page into naitaionitem.title every time I transition to the page.


when inserting characters into navigationitem.title Count the number of characters each time, and if it is more than a certain number of characters,

Cut the end of the string before inserting,
It may be possible to implement
It is troublesome because it is necessary to do that every time.
If there is something that can be set up in bulk, it would be difficult to find it.

The environment is
El Capitan, Swift2, Xcode 7.0.1.
Thank you.

Enter a description of the image here

swift objective-c xcode

2022-09-29 22:38

1 Answers

let overCount: Int=// character limit
var navigationTitle: String?{
    DidSet{
        if var title = navigationTitle {
            if title.count<=overCount{
                navigationItem?.title=title
            } else{
                title=String(title.prefix(overCount))
                title+="…"
                navigationItem?.title=title
            }
        }
    }
}

Is it possible to do it in ?


2022-09-29 22:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.