#UIToolbar
Explore tagged Tumblr posts
yogeshpatelios · 5 years ago
Video
youtube
Swift 5 & Xcode 11 : UIDatePicker as inputView to UITextField With UIToo...
0 notes
goodorbetterprogrammer · 3 years ago
Text
HackingWithSwift Day 24/25/26
Introduction to WKWebview
“The delegation solution is brilliant: we can tell WKWebView that we want to be informed when something interesting happens. In our code, we're setting the web view's navigationDelegate property to self, which means "when any web page navigation happens, please tell me – the current view controller.” Definition of delegation by the author, this will comes in handle when we create our own custom delegate after this.
class ViewController: UIViewController, WKNavigationDelegate
Parent class comes first, then only protocol next
@objc func openTapped() { let ac = UIAlertController(title: "Open page…", message: nil, preferredStyle: .actionSheet)        ac.addAction(UIAlertAction(title: "apple.com", style: .default, handler: openPage))        ac.addAction(UIAlertAction(title: "hackingwithswift.com", style: .default, handler: openPage))        ac.addAction(UIAlertAction(title: "Cancel", style: .cancel))        ac.popoverPresentationController?.barButtonItem = self.navigationItem.rightBarButtonItem        present(ac, animated: true) }
func openPage(action: UIAlertAction) { let url = URL(string: "https://" + action.title!)!        webView.load(URLRequest(url: url)) }
action.title is refer to the title set at the new instance of UIAlertAction
================== And the very first delegate we use under WKNavigationDelegate
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {        title = webView.title }
Whenever web view finished load a page, it will change the navigation title to be the same as web view title
==================
Now introduce UIToolbar and UIProgressView
var progressView: UIProgressView = UIProgressView(progressViewStyle: .default) progressView.sizeToFit() let progressButton = UIBarButtonItem(customView: progressView)
let spacer = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil) let refresh = UIBarButtonItem(barButtonSystemItem: .refresh, target: webView, action: #selector(webView.reload))
toolbarItems = [progressButton, spacer, refresh]
Wrap the progress button in UIBarButtonItem and add it to toolbarItems =============
Key-value observing (KVO)
To update the progressView we need to know the web view loading progress
webView.addObserver(self, forKeyPath: #keyPath(WKWebView.estimatedProgress), options: .new, context: nil)
Usually when do addObserver(), one need to take care of removeObserver() to ensure everything run fine
Then add the following method to get the value
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {    if keyPath == "estimatedProgress" {        progressView.progress = Float(webView.estimatedProgress)    } }
Since we want to observe the key path of WKWebView.estimatedProgress, then inside the method, we check if the key path of the value is actually same as WKWebView.estimatedProgress. If it’s the same, we get the estimate progress and update the progressView progress.
The extra float casting is needed since webView.estimatedProgress is a Double, and progressView.progress only accept Float.
================= func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {    let url = navigationAction.request.url
   if let host = url?.host {        for website in websites {            if host.contains(website) {                decisionHandler(.allow)                return            }        }    }
   decisionHandler(.cancel) }
To ensure user can’t navigate to other page, need this delegate method to control the site, but need to read more on @escaping closure
===================
0 notes
goodanswerbiz · 10 years ago
Text
Fixed Creating a left-arrow button (like UINavigationBar's "back" style) on a UIToolbar #dev #it #asnwer
Fixed Creating a left-arrow button (like UINavigationBar's "back" style) on a UIToolbar #dev #it #asnwer
Creating a left-arrow button (like UINavigationBar’s "back" style) on a UIToolbar
I’d love to create a “back” left-arrow-bezel button in a UIToolbar.
As far as I can tell, the only way to get one of these is to leave UINavigationController at default settings and it uses one for the left bar item. But there’s no way I can find to create one as a UIBarButtonItem, so I can’t make one in a standard…
View On WordPress
0 notes
olegsl · 12 years ago
Text
iOS Марафон. 2 День
Сегодня 2 день марафона и задание на сегодня будет не на много сложнее чем в вчера :) Но прежде чем приступить к выполнению задания, я хочу по приветствовать моего друга Кирилла который тоже принял в devel-забеге.
Заданием на сегодня будет простая вещь, а именно работа с UINavigationBar и UIToolbar. Общий смысл приложения можно представить в виде такого "мокапа"
Tumblr media
 Это будет небольш��й каталог птиц, где каждая иконка на toolbar веден на описание страницы определенной виды птицы. На первой страницы указан заголовок, изображение краткое описание и кнопка подробнее (конечно совершенно не нужное с точки зрения дизайна). Кнопка подробнее открывает другую страницу, где есть только текст.
Все данные статичные. Информация взята из википедии.
Итак открываем наш проект checkout на master и создаем новую ветку birdlist.
После часа работы у меня так не получилось сделать то что задумал, все выглядит криво и косо :(
http://youtu.be/jiyZKI-BZn8
К сожалению у меня больше нет времени исправить косяки, нужно собираться ехать в командировку. Возможно под стук колес все исправлю... :)
0 notes
alldonegoodbye · 12 years ago
Link
self.navigationController.toolbarHidden=NO; UIBarButtonItem *flexiableItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:nil]; UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:nil]; NSArray *items = [NSArray arrayWithObjects:item1, flexiableItem, item2, nil]; self.toolbarItems = items; [flexiableItem release]; [item1 release]; [item2 release];
or
self.navigationController.toolbarHidden=NO; UIBarButtonItem *flexiableItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:nil]; UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:nil]; self.toolbarItems = @[item1, flexibleItem,item2];
1 note · View note