Change Layout for UISegmentedControl? - iphone

currently I'm using the SVSegmentedControl by Sam Vermette - works great, but I'm asking myself if it's possible to change the layout of the SVSegmentedControl or the UISegmentedControl in general?
I want to have 2 rows with 2 "cells" / row, is that somehow possible?
Thanks

If you want to have 2 rows, each with two cells, this isn't a thing that you can change with default segmented control behavior.
If you want something that looks like a box with 4 sections and behaves like a segmented control (only allows one part to be selected) then create 2 segmented controls. Customize how "it"(they) look(s) with backgroundImageForState:barMetrics: and other similar methods. When you detect that one of the control's parts has been selected, then deselect all of the other parts in both controls.

If you look at the source code, it doesn't actually inherit from UISegmentedControl, instead from UIControl. So if you wan't to customise UISegmentedControl, your best bet looks like building a similarly behaving control from scratch.

Related

Swift - UISwitch as selector between two values?

I want as an option in an app I'm building to offer the user to select between seeing temperatures in Celsius (C) or Fahrenheit (F). This option will be shown within a tableview controller.
My initial thought was to use an UISwitch for this but this would require adding labels left and right of the UISwitch and linking the on/off to either C or F.
Is there a better way or will I need a custom control for this?
Thanks!
Kostas
I would use UISegmentedControl for that:
It would look like that:
As you see you can make multiple items so if there is another option to choose, you can easily add it.

What's the best way to customise all monotouch.dialog TableViewCells to the same style (Background, etc..)?

Im using Monotouch.Dialog. I'd like to customise the look and feel of the tables. Nothing too major, I can change the background of the tableview easily, the cell borders and use my own custom header and footer views.
What is the best way of customising ALL the cells displayed in a TableView?
Is there some point in the Monotouch.Dialog code I can intercept the generation of cells and customise them in one place, so they all, for example have the same background color, font type/color custom detail disclosure icon etc.
Or do I have to individually customise all the different types (BooleanElement, StringElement, FloatElement etc)
Note: Im aware I can use StyledString element, but this only covers the string element type. I want to customise all the cells displayed in my own custom style.
There is no easy way of doing this in the current codebase for MonoTouch.Dialog.
What you could try is the Beta for MonoTouch which comes with iOS5 bindings. If you are willing to only support iOS5, you can use the Appearance class to customize a few properties (not all, sadly). You can customize things like the background view across the board:
UIView.Appearance.BackgroundColor = UIColor.Red;
You could also take a look at https://github.com/RobertKozak/MonoMobile.Views which started as a fork from MonoTouch.Dialog but morphed into a similar but now totally different library. It has styling built in.

Best approach to create a "settings" dialog page in iPhone [duplicate]

This question already has answers here:
How to create a UITableView with editable components?
(2 answers)
Closed 3 years ago.
I need to present the user with a screen with controls (i.e. a dialog). It will display some labels and different types of controls so that the user can do some configuration:
select a color (custom color picker)
select a line width (slider)
select one value from a list of values (UISegmentedControl?)
enable / disable one option (On/Off)
...
I am evaluating different alternatives:
Create the layout with labels and controls in InterfaceBuilder
Use a UITableView, so that each cell contains a label and its control
I like option 2 because it is similar to iPhone Settings app, and it makes the screen look organized, giving you sections, scroll..., but it is a real pain to create in code all different cell layouts, taking into account each row heights...
The solution has to be easiliy maintainable, allowing easy reuse of code, DRY (low repetition), data-driven...
Is there a recommended or standard aproach to do this?
Instead of implementing it yourself you might also like to consider some of the open source solutions. I use InAppSettingsKit in my app. There are a few minor UI glitches but it works well. I also evaluated mySettings (indeed I submitted a couple of patches) and InAppSettings.
Even if you don't use them, you might be able to crib a few ideas from them.
You can create the tableview cells in IB and then just create IBOutlets to each cell, and then return each cell in the data source method (forgotten the exact name of it, its where you normally create cells)
You could create a cell in IB for each cell or create different types of cells in IB, say one slider based cell, etc and programmatically change the text, etc.
This is staticly creating a tableview, theres an Apple guide on it somewhere.
you said it. use a UITableView and create custom UITableViewCells (probably in Interface Builder!) and add these in.
Also, as far as selecting a value from a list of values.. a drill in UITableView (embed the root UITableView in a navigation controller) with all the options and then a checkmark is probably advisable (this is how most apps handle this behavior). The On/Off button is more suited for UISegmentedControl.
There are great examples of this in this book.
Good luck.

Reordering Cell Icon Customized

I have a table view in which i am reordering my cells
Now the issue is that the client doesn't like the icon of the reorder (i.e. 3 horizontal lines)
Is there any way you can help out.
First of all I want to know Is it possible at all?
You cannot change the standard icon. But you should be able to use a custom button and start/end editing mode programmatically (haven't tested this).
If it isn't a very custom UI at all, tell him that messing with standard icons/behavior is the best way to make users frustrated.

How can I enable multiple segments of a UISegmentedControl to be selected?

Lets say my UISegmentedControl has 8 numbered segments. I would like for the user to be able to turn on 2, 3, or more of them at once. Toggling them. Essentially like a bits in a byte. Is this possible? I believe it is on regular Mac OS X but I can't seem to find a way to do it in the iPhone SDK.
If I have to simulate this by putting buttons into a view, is there any way to do the following:
Round the corners of the view so that it looks like the "bar" style UISegmentedControl?
Use the built-in backgrounds the "bar" style has on the buttons?
Give the buttons a shadow like the whole "bar" style has? (not the text)
Update: The custom control I mentioned here no longer works under iOS 13.
This is the best custom control I've found that allows multiple segments to be selected concurrently:
https://github.com/yonat/MultiSelectSegmentedControl
This one is a subclass of UISegmentedControl, which is convenient. I've forked it here:
https://github.com/stewartmacdonald/MultiSelectSegmentedControl
and added some code examples to the ReadMe and added a method that allows you to get an NSArray of the titles of all selected segments.
This isn't possible using UIKit. I would recommend creating a custom control, or an array of UISwitch controls, representing each of the options in your UISegmentedControl.
I think the simplest way is to create your own segmentedcontrol with UIButton.
Marco
There appears to be a way to do this in XCode now. In the Attributes Inspector, there is a section with Segment, Title, Image, Behavior. The behavior options are "Enabled" and "Selected". You can selecte "Selected" for multiple segments.
I recommend you try https://github.com/tayhalla/THSegmentedControl
it is an actual subclass of UISegmentedControl so it fits nicely with Interface builder and everything.