How to load ActivityIndicatorView on TableView inside TabBarcontroller, XCode 4.2 - uitabbarcontroller

Xcode - version 4.2
Target Platform - iPhone
I have a TabBarController , containing 3 tabs. All tabs contain TableViewController wired to the TabBarController via NavigationController. All TableViewController shows data from external URL, and as well have their corresponding DetailViews.
The application works all fine.
I'm unable to add an 'UIActivityIndicatorView" while the data on the TableView is being loaded. The 'storyboard' neither allows me to add the 'UIActivityIndicatorView' control on the TableViewController or UINavigationController.
Note :
I understand placing UIActivityIndicatorView directly on a UIViewController.
I dont want the UIActivityIndicatorView 'loading' for the cells in the TableView.
Thanks,
Sriram

I'm trying to do the same with Storyboard but it seems that you should bette do it programmatically :
In your ViewController.h :
#property (strong) UIActivityIndicatorView *activityIndicator;
In viewDidLoad :
// init with desired state
activityIndicator = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
// set the color
activityIndicator.color = [UIColor blackColor];
activityIndicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
// set the position
activityIndicator.center = CGPointMake(self.view.bounds.size.width/2,
self.view.bounds.size.height/4);
If you have to handle orientation change, think to update the position in viewWillAppear and willRotateToInterfaceOrientation
I think I'll loose less time to code that than time to find a better way to work with Storyboards

Related

Setting the font of SwiftUI's .searchable() with the appearance API of UITextField+UISearchBar doesn't work

I'm customizing the appearance of the .searchable() modifier of SwiftUI with the appearance API of UISearchBar.
Almost everything works, except the font of the text field, and I have no idea why (setting the font of the cancel button works, or setting the background color or text color of the text field also work, so the correct reference is there).
Talk is cheap, show me the code!
let textAttributes: [NSAttributedString.Key: Any] = [
.foregroundColor: UIColor.systemBlue, // this works
.font: UIFont.boldSystemFont(ofSize: 15) // this doesnt
]
let placeholder = NSAttributedString(
string: "Search...", // this doesnt
attributes: [
.foregroundColor: UIColor.systemGray, // this works
.font: UIFont.boldSystemFont(ofSize: 15) // this doesnt
])
let textFieldAppearance = UITextField
.appearance(whenContainedInInstancesOf: [UISearchBar.self])
textFieldAppearance.backgroundColor = .red // this works
textFieldAppearance.defaultTextAttributes = textAttributes // color works, font not
textFieldAppearance.attributedPlaceholder = placeholder // color works, font or text not
I guess it's time to file a -radar- feedback?
I haven't found a reliable way of customizing this, with the solution posted below there's a glitch on the search bar that happens when SwiftUI re-renders the view (scrolling or just typing on the search bar), that is very obvious on a real device (not so much on the simulator).
Old answer:
Far from ideal, I found a way to make it work, which is introspecting the view searching for the UITextField and setting the font directly. The easiest way to do this is using a library like SwiftUI-Introspect (https://github.com/siteline/SwiftUI-Introspect).
Then on the View you're using .searchable() from just:
.introspectTextField { textField in
textField.font = UIFont.boldSystemFont(ofSize: 15)
}
Fixed! The perfect solution would be to use the appearance API, but I guess we'll have to wait till iOS 16...
Setting the .font and .foregroundColor modifiers after .searchable will do the desired result, but it still doesn't work with .background modifier (if you want it) as the time of this writing (iOS 16).

iOS 11 inputAccessoryView broken

I have the following set up for my UIToolBar / Accessory View on a view controller
#IBOutlet var inputFieldView: UIToolbar!
override var canBecomeFirstResponder: Bool{
return true
}
override var inputAccessoryView: UIView?{
return self.inputFieldView
}
then inside my viewDidLoad I have:
let seperator = UIView(frame: CGRect(x:0 , y: 0, width: ScreenSize.width(), height: 1))
seperator.backgroundColor = UIColor.lightBackground
self.inputFieldView.addSubview(seperator)
self.inputFieldView.isTranslucent = false
self.inputFieldView.setShadowImage(UIImage(), forToolbarPosition: .any)
self.inputFieldView.setBackgroundImage(UIImage(), forToolbarPosition: .any, barMetrics: .default)
self.inputFieldView.removeFromSuperview()
This worked great for ios versions 10 and 9. It is a text view with a "Send" button. It sits at the bottom of the screen and when pressed, becomes first responder allowing the keyboard to come up and it positions itself correctly.
With ios 11 i cannot even click on it when it is at the bottom, so I cannot type at all.
This is a known bug on iOS 11. UIToolbar subviews don't get the touch events because some internal views to the toolbar aren't properly setup.
The current workaround is to call toolBar.layoutIfNeeded() right before adding subviews.
In your case:
inputFieldView.layoutIfNeeded()
Hopefully this will get fixed on the next major version.
Solved it. It looks like UIToolbar's just are not working correctly in iOS 11.
Changed it to an UIView and removed
self.inputFieldView.isTranslucent = false
self.inputFieldView.setShadowImage(UIImage(), forToolbarPosition: .any)
self.inputFieldView.setBackgroundImage(UIImage(), forToolbarPosition: .any, barMetrics: .default)
got it working (and changed it to a UIView from UIToolbar in the xib as well.)

displaying image in a toolbar in swift 3

i am trying to create a toolbar with buttons. and the button i want to have is an image rather title. The current non working code is:
let imageName = "yourImage.png"
self.myUIBarButtonBack = UIBarButtonItem(image: UIImage(named: imageName), style:.plain, target: self, action: #selector(onClickBarButton))
I have 2 questions:
1. where should i place the yourImage.png in my application
2. is this code sufficient to render image or i need to do things like putting it into imageView component and make it visible etc. ?
The best approach is to add images in xcassets. This is the best way you can organize images. The concept of App slicing applies here.
You don't need to put the image in image view in the case of bar button item.
Try changing the rendring option as Original Image instead of Default.
One way is create custom button and assign to toolbar like navigationbar
self.navigationItem.hidesBackButton = true
let button = UIButton.init(type: .custom)
button.setImage(UIImage.init(named: "back_icon"), for: UIControlState.normal)
button.addTarget(self, action:#selector(onClickBackBarItem), for: UIControlEvents.touchUpInside)
button.frame = CGRect.init(x: 0, y: 0, width: 25, height: 25)
let barButton = UIBarButtonItem.init(customView: button)
self.navigationItem.leftBarButtonItem = barButton

Add UINavigation Back button in UICollectionView with Swift 3

I add Left Navigation Back button in collection view controller with code.
//Add Navigation Bar
navbar.autoresizingMask = [.flexibleWidth, .flexibleBottomMargin, .flexibleRightMargin]
navbar.delegate = self
UINavigationBar.appearance().barTintColor = UIColor(red: 0.0/255.0, green:49.0/255.0, blue:79.0/255.0, alpha:0.1)
UINavigationBar.appearance().tintColor = UIColor.white
UINavigationBar.appearance().isTranslucent = true
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.white]
navItem.title = prefs.value(forKey: "PROVIDER_NAME") as! String?
let image = UIImage(named: "back_image")
navItem.leftBarButtonItem = UIBarButtonItem(image: image, style: .plain, target: self, action: #selector(addTapped))
navItem.leftBarButtonItem?.imageInsets = UIEdgeInsetsMake(0, 0, 0, 0)
Back button is so close to the left. I would like to add padding about 10px from the left. So, I changed the code into
navItem.leftBarButtonItem?.imageInsets = UIEdgeInsetsMake(0, 15, 0, 0)
but it is not working and image Back button looks smaller. How can I do to add space to the left of Back button?
I would recommend replacing UINavigationBar with a simple UIView. This way you would gain a full control over the layout of the navigation bar. It wouldn't be anything more than a transparent UIView with a back button and a title label inside. As simple as that.
The real UINavigationBar is more than that. It's meant to manage a stack of UINavigationItem objects. It adjusts itself depends on the current item and knows how to make an animated (and even interactive) transition from one state to another. That's why you can't change much about the bar's appearance. You shouldn't treat it as a regular view.
UPDATE
Another way to achieve this is a little tricky. You can implement it completely from a storyboard and you don't need mess with appearance.
Add UINavigationBar to a view controller.
Add a plain UIView to the left side of UINavigationBar and make its background color completely transparent.
Add UIButton to the view added in the previous step and set a back icon as its image.
Add constraints to the button to align it to the right side of its superview.
Adjust the width of the view so the back button position is exactly where you want it to be.
This is a view hierarchy in the storyboard:
This is how your UINavigationBar will look like (for you the background will be transparent):

iOS 5 Storyboard: NavigationViewController to TabbarController - Not working , Why?

I am using iOS5 with Storyboard and my scenes are like this :
NavigationCOntroller ->(Nav view 1) TableViewController -> TabBarController ->(Tab1)TableViewController
and similarly I more tabs under my TabBarController.
Now I go to Tab1 when user clicks on any row in my TableViewCOntroller and before PerformingSegue I want to send some data to my Tab1(TableViewController) like this
MyTableVController *tvc = segue.destinationViewController;
tvc.selectedObject = currentObject;
[UITabBarController setSelectedObject:]: unrecognized selector sent to instance 0x68c9450
Now why is it assuming that 'MyTableVController' is a UITabBarController and searching for setSelectedObject method ???
And how can I pass data to my TableViewCOntroller in this scenario ?
Thanks.
OK I have found solution to my problem , I did like this
UITabBarController *tabController = (UITabBarController *)segue.destinationViewController;
MyTableVController *tvc = (MyTableVController *)[viewControllers objectAtIndex:0];
And thats how you have your required viewcontroller and pass data to it.