Navigation bar large title not indenting
I have a large title navigation and the title is not being indented to be in line with the UIBarButton items.
How do I fix this?:
Any help would me much appreciated, thanks.
See also questions close to this topic
-
How can I automate a project developed in Swift?
How can I automate project developed in Swift?
-
Parsing JSON data from an embedded navigation controller table view to a new view controller Swift IOS
I'm having a navigation controller with a table view and i pulling json data it displays it but i want to parse the data to a new view controller when a table cell is selected it displays a black screen This is the first screen and I want to parse data to a new view when a cell is selected here is part of the code
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { self.selectedEvents = self.events[indexPath.row] self.performSegue(withIdentifier: "goToEvent", sender: self) } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "goToEvent" { if let navController = segue.destination as? UINavigationController { if let chidVC = navController.topViewController as? EventDetailViewController { chidVC.selectedEvents = self.selectedEvents } } } }
var selectedEvents: Event? override func viewDidAppear(_ animated: Bool) { print("Loading") if let eve = self.selectedEvents { self.eventLabel.text = eve.name self.locationLabel.text = eve.loca self.desclabel.text = eve.desc self.dateLabel.text = eve.dat self.timeLabel.text = eve.tim self.idLabel.text = eve.idd let width = self.view.frame.size.width let height = width/320 * 180 self.imageLayoutConstraint.constant = height Alamofire.request((selectedEvents?.banner!)!).responseImage { response in debugPrint(response) print(response) if let image = response.result.value { //cell.eventImage.image = image self.eventImageView.image = image } } Alamofire.request((selectedEvents?.log!)!).responseImage { response in if let image = response.result.value { self.eventImageView.image = image } } } }
-
Error casting variable opening plist file from bundle Cast from 'Data?' to unrelated type '[[String : Any]]' always fails
I'm opening plist file and trying to cast the variable into an Array
[[String: Any]]
but I'm getting this error"Cast from 'Data?' to unrelated type '[[String : Any]]' always fails"
Here is my code:
let myVariable = (try fileManager.contents(atPath: documents) as! [[String: Any]])
My question to you guys is how can I can convert or cast the contents of the plist as an Array?
I'll really appreciate your help.
-
Swizzling Font Descriptors for Storyboards and Nibs
Is it possible to swizzle the font descriptors that are used in Storyboards and Nibs like you could with code instantiated fonts?
class func overrideInitialize() { guard self == UIFont.self else { return } if let preferredFontMethod = class_getClassMethod(self, #selector(preferredFont(forTextStyle:))), let myPreferredFontMethod = class_getClassMethod(self, #selector(myPreferredFont(forTextStyle:))) { method_exchangeImplementations(preferredFontMethod, myPreferredFontMethod) } } @objc class func myPreferredFont(forTextStyle style: UIFontTextStyle) -> UIFont { switch style { case UIFontTextStyle.body: return UIFont(name: "SomeFontName", size: 17)! ... default: return UIFont(name: "SomeFontName", size: 17)! } }
Right now I can successfully swizzle fonts they are used in code but none of my storyboard texts are swizzled.
-
How To Add New Rows To The Top of theTableView in Swift?
I am new to swift and trying to improve myself. For now i am trying to make a single view app that when you press the button, app will add a new row. When slide to left, delete button will appear and it will delete the row. Everything looks fine by me but I am getting the error
attempt to insert row 3 into section 0, but there are only 0 rows in section 0 after the update
Here is my
ViewController
:import UIKit class MusterilerViewController: UIViewController, UITextFieldDelegate { @IBOutlet weak var addVideoTextField: UITextField! @IBOutlet weak var tableView: UITableView! var array: [String] = ["First", "Second", "Third"] override func viewDidLoad() { super.viewDidLoad() tableView.tableFooterView = UIView(frame: CGRect.zero) } @IBAction func addButtonTapped(_ sender: YTRoundedButton) { insertNewVideoTitle() } func insertNewVideoTitle() { if addVideoTextField.text!.isEmpty { print("Add Video Text Field is empty") } if addVideoTextField.text == ""{ return } array.append(addVideoTextField.text!) let indexPath = IndexPath(row: array.count - 1, section: 0) tableView.beginUpdates() tableView.insertRows(at: [indexPath], with: .automatic) tableView.endUpdates() addVideoTextField.text = "" view.endEditing(true) print(array) }} extension MusterilerViewController: UITableViewDelegate, UITableViewDataSource { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return array.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let videoTitle = array[indexPath.row] let cell = tableView.dequeueReusableCell(withIdentifier: "VideoCell") as! VideoCell cell.musteriTitle.text = videoTitle return cell } func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { return true } func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == .delete { array.remove(at: indexPath.row) tableView.beginUpdates() tableView.deleteRows(at: [indexPath], with: .automatic) tableView.endUpdates() } }}
Edit: It is not a duplicate question, even the logic may be similar but problem is different and also this is in swift language.
-
Xcode 9 code sign error code 1
I have tried cleaning my build folder, deleting the provisioning and certificates for the app, deleting derived data, and manually managing signing yet no matter what I do, I cannot get the build to archive. I get one erorr in xcode:
/Users/jscotto/Library/Developer/Xcode/DerivedData/ionic-deep-links-cdaztiimhbiwroaimkxbkdasbvpy/Build/Products/Debug-iphoneos/ionic-deep-links.app: unknown error -1=ffffffffffffffff Command /usr/bin/codesign failed with exit code 1
I have no clue what could be causing this.
-
How to get section Header value From cell Swift
In my DidselectRowAt method I have a cell that I get using
let currentCell = tableView.cellForRow(at: indexPath) as! SongCell
However Mutilating this cell causes issues considering the table view Im in has multiple section Headers like this :
How Can I tell what section header my cell has so when I change the image on the right to gray , other cells in the tableview dont change? Thank you.
-
How to control multiple navigation controller in an iOS project
The structure of my project is as follows.
Initially when the user is registering or trying to login the initial navigation controller should work and after successfully registering / loggin in the user should be taken to first tab of tab bar controller. But the issue that i am facing is that i am getting 2 navigation bars in the tab bar view. Can someone guide me how to implement this in the correct way.
Thanks in advance
-
Shadow on custom navigation bar button item clipping to bounds
I have a back button item on my navigation bar that I want to use include a drop shadow on but the drop shadow clips to the navbar bounds. Is it possible shadows extend past the bounds of the navbar?
I've simplified and greatly exaggerated the effect in this example:
The code for the button looks something like this:
let button = UIButton(); button.layer.shadowOffset = CGSize(width: 0, height: 12); button.layer.shadowColor = UIColor(red: 0.06, green: 0.09, blue: 0.13, alpha: 0.8).cgColor; button.layer.shadowOpacity = 1; button.layer.shadowRadius = 14; button.backgroundColor = UIColor(red:0, green:0.65, blue:0.57, alpha:1); button.layer.cornerRadius = 20; button.translatesAutoresizingMaskIntoConstraints = false; button.widthAnchor.constraint(equalToConstant: 40).isActive = true; button.heightAnchor.constraint(equalToConstant: 40).isActive = true; self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: button);
I also set my navigation bar to transparent with the following code:
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default); self.navigationController?.navigationBar.shadowImage = UIImage(); self.navigationController?.navigationBar.isTranslucent = true;
I've already tried a setting clipsToBounds and layer.masksToBounds to false on the navigationBar but that doesn't fix the issue. I figure as a hack I could probably just increase the size of the navigationBar and reposition the button so the shadow doesn't clip the statusBar but hoping someone knows a more ideal solution.
-
iPhone X issue with an UICollectionView and its Header (NavigationBar conflict)
I have an issue while designing my UIViewController for the iPhone X.
Instead of writing a long explanation of my issue, I will show you some screenshots, it will be more understandable.
Basically, the ViewController contains an UICollectionView (clear blue) with its constraints set to the superView.
The green View is a Collection Reusable View, which is the Header of the Collection View.
The dark blue View is just an UICollectionViewCell, it doesn't matter.
Keep in mind that my Home ViewController is embedded in a Navigation Controller, and for this screenshot I have hidden the Navigation Bar.
Now let's have a look with a Navigation Bar shown :
Additional Informations :
I have a Background ImageView in my Header (the green View).
What if I want the image to take the whole Navigation Bar + Status Bar ?
I mean, is it possible to make the Header of the UICollectionView going to the top of the screen ?
Here is the result on the simulator :
I want a transparent Navigation Bar + the Background image from Header going to the edge of the screen.
If you have any advices or useful informations, I will take anything.
-
Issue with search bar in iOS 11 have large titles
I have enabled large titles and have applied color on navigation bar. Now when i am scrolling, it is showing a white bar above searchbar.
Here is the Sample. Also i am facing this issue on Real device.
Thanks
-
Q: Swift large titles transition animation bug
Has anyone else experienced the following whilst transitioning back to a controller using large titles?
Nothing special going on here, using a tabBarController with an embedded navigationController. However the issue persists if this is just an navigation controller.
Likewise the issue persists when the search controller hasn't been added.
The navigation title is setup in viewDidLoad and prefersLargeTitles is set in viewWillAppear.
-
Programmatic beginRefreshing() on iOS11 has problems with largeTitles mode
We have found what seems to be a bug in UIKit but wanted to post here to see if anyone else has this problem or found a solution.
We're trying to use the new iOS11 large titles and hoisted search bar/refreshcontrol. We seemed to have found a problem where the root viewController of the navigation stack shows a minor display issue (problem A) but once another viewcontroller is pushed onto the navigation stack, the display goes nuts (problem B):
Things to note:
- The problem is worse on the 2nd VC in the stack rather than the 1st
- The refreshControl is not the green color the code sets it to the 1st time you see it on each sceen
- The refreshControl slides down as you pull to refresh, it shouldn't do this
This odd behavior seems to only be a problem when we programmatically do a "pull to refresh" in viewDidLoad so that the user can see that the data is loading when they enter the screen. If we remove the lines that invoke
refreshControl?.beginRefreshing()
the display is clean. I've recreated this problem in a sample vanilla app. This is the entirety of the viewcontroller that shows the problem:import UIKit class ViewController: UITableViewController { var tableHeaderSearchController: UISearchController! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. self.navigationController?.navigationBar.prefersLargeTitles = true self.navigationController?.navigationItem.largeTitleDisplayMode = .always tableHeaderSearchController = UISearchController(searchResultsController: UITableViewController()) navigationItem.searchController = tableHeaderSearchController refreshControl?.tintColor = UIColor.green refreshControl?.backgroundColor = UIColor.clear refreshControl?.attributedTitle = NSAttributedString(string: "Loading Stuff...", attributes: [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 17)]) refreshControl?.addTarget(self, action: #selector(refreshPulled), for: .valueChanged) // Commenting out these 2 lines makes it work fine but you can't see the initial refresh spinner refreshControl?.beginRefreshing() refreshPulled() } @objc func refreshPulled() { DispatchQueue.main.asyncAfter(deadline: .now() + 3) { [refreshControl] in refreshControl?.endRefreshing() } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
Here's the storyboard. It's just a vanilla tableviewcontroller wrapped in a navigationController. 3 static cells, the 2nd one traverses to another instance of the same controller type.
Any ideas would be greatly appreciated. We'd really like to adopt the new look but this stuff is making it very hard to do so.