How to add two custom rightBarButtonItems without a margin between them? - iphone

I create UIToolbar with interface builder and want to add two custom right buttons, but without a space between them. I don't want solution to reset a margin from the right edge, because I found it here but want only reset margin between buttons.
How should I do this?
Thanks.

Instead of a button, use an UISegmentedControl and set its momentary property to yes.
Add one segment for each button you want (in this case two segments)
Then add an IBAction and use a switch to know what index has been selected.
Index 0 first button, index 1 second button.

Create a bar button item with a custom view where that custom view has 2 UIButtons as subviews. In this way you can exactly size and position the buttons as you require.

To adjust space between UIBarButtonItem's you can use a UIBarButtonItem with style UIBarButtonSystemItemFixedSpace and setting its width property.
You can move items closer to eachother than the default spacing by setting the width of the spacer item to be a negative value.
One thing to consider is future-proofing whichever solution you choose. Buttons in iOS6 have nice borders and shading. They may not in the near future...

Related

Why Xcode Storyboard preview and emulator button texts are not compatible?

I am trying to drag and drop buttons to the storyboard. The buttons seem good in my storyboard and preview like the following;
However, when I run the simulator, the button texts seem like the following;
Why the buttons are not shown to fit in the buttons of the simulator and how can I fix this?
Note: Preview and device types are iPhone13 Pro.
The iOS 15 / Xcode 13 style buttons are highly dependent on auto-layout.
Based on your screen-shots, it doesn't look like you've given the buttons any constraints.
You do NOT need to set widths or heights, but you DO want to set at least horizontal and vertical position constraints.
So, constrain all 4 of your buttons centered horizontally, and constrain:
First button Top to view Top (safe area)
Second button Top to First button Bottom
Third button Top to Second button Bottom
Fourth button Top to Third button Bottom
Then you should see them laid-out correctly at run-time.
I think it's because of the auto layout constraints. I am not very familiar with storyboards, if you don't set width of the view component, it seems fine on the storyboard but when compiling the view it actually has default size.
Try to set some constraints for width. Maybe it would help.
The first thing you need to do is to create identical buttons with identical size and with identical font size.
As you can see in your project, the buttons have different sizes, but the text is the same size in all buttons.
To make it faster - you can create one button and make a copy with option + drag’and’drop…
Then, you can put them in a Stack View. So, it will be easier for you to work with them in the future.
Select all buttons and make a Stack View...
https://i.stack.imgur.com/QLTJP.png
https://i.stack.imgur.com/OlOia.png
After that, resize your Stack View like you want.
Then, tap on a Stack View and clear the constraints.
https://i.stack.imgur.com/1pMT8.png
Fix the dimensions like this. But, without “Constrain to mergins”.
https://i.stack.imgur.com/8HKKF
After that, make for the Stack View - horizontally and vertically position in your storyboard.
https://i.stack.imgur.com/a29wL.png
The result is…
https://i.stack.imgur.com/mvQjg.png
Hope it’s break your problem! :)

Swift Color picker for user

I need some help on best direction for creating the following:
An Colours picker that shows a number of colours as small circles
Selected colour is a bigger circle
Allow user to click to select their colour
See image for example of what I mean
I am a bit lost in the best way to create this, I am not looking for the code it self just a direction to go by to create this :)
Using UICollectionView is the easiest available option.
1) Option 1
Use a custom UICollectionViewCell.
Add a view in it with constraints with respect to the superview i.e CollectionViewCell.
Give corner radius to the view to make it a circle.
On selection of the particular collectionViewCell, Update the size of the view and the corner radius to make the circle bigger.
Note : Save the indexPath of the previously selected cell if you want to decrease the size of the previously selected colour option.
2) Option2(Not suggested):
If the numbers of colours are limited. Use a stackView with buttons.
Customise the buttons to the required shape.
Updated the size of the button with respect to the superview i.e Stack.
You can have a single outlet for all the buttons. But you will have to save the instance of the selected button so as to update the previously selected button.

Common UIToolbar for the required pages - Xcode 8.3

Please suggest that how we can create common UIToolbar(with bar items) for the required pages?
I know that we can add custom UIBarButtonItem in each view controller.
Assuming you use storyboard. First, drag a UIToolBar item to your storyboard.
Next, set up the location of the tool bar. In my example, I put it on the bottom with padding 0 to left, right and bottom. The height is set to be 44
Finally, drag as many Bar Button Item as you want to your tool bar, and then add spaces between them. You can either use fixed length spaces, or the flexible ones (which are used in this example) by simply drag them between the bar button items.

custom UIToolbar without using background image

I want to make uitoolbar to have separation like this one. But i do not want to use it as background image.
any idea how to do it?
This one is only three section, and if it has four section of course the column will become have four section.
Thank you
You can use 3 buttons instead of toolbar and for separation you can adjust the frame of buttons accordingly. Give it a try. This will look like toolbar.

iphone uitablecellview overflow

Is there a way to hide the overflow in a UITableViewCell? I have a custom cell view, that I load into the table, where some of the information is supposed to be hidden on load, and then each row will expand when clicked.
Right now, I'm returning height 30 for my row, which is the height of the cell header, but the buttons and text that are supposed to be hidden just overflows and is placed on top of the headers below.
While you can use clip subviews(cell.contentView.clipsToBounds = YES), it's probably best if you add the subviews when you need to expand and remove the subviews the cell collapses. It should increase performance.
There's a property on UIView "clips subviews?".
If you set this value TRUE for the cells, it should stop the buttons from overflowing - you can do it either in IB, or in code programmatically (slightly different name in code).
HOWEVER ... this may NOT be what you want. Depends on the effect. Last time I did what you're doing, I used clipsubviews.
Usually, the correct way to hide your buttons etc is the UIView property "hidden" (or the other one - "enabled").
But that might mess with your animations - depends how you're animating the click-to-expand.