is it possible to change UI of widget after expanding it?

I am making a widget which shows 4 circular progress bars regarding some data. I want that when the widget is expanded, instead of one row of 4 circles, the 4 are arranged in rows along with buttons and data concerning them.


So lets say the alphabet O represents one such progress bar.


Before expandning Widget

O O O O


after expanding

O some buttons or text

O some buttons or text

O some buttons or text

O some buttons or text


Is this possible?

Replies

How do you define widget ? By code ? In IB ?

Could you show code.


One suggestion (but I've not developed widgets so far) would be to:

- define constraints between the 4 buttons (or text) so that they align:

btn2 leading to btn1 leading = 40 // spacing

btn2 top to btn1 top = 0

- Connect the constraints to IBOutlets

    @IBOutlet weak var bt2ToBtn1HorizConstraint: NSLayoutConstraint!
    @IBOutlet weak var bt2ToBtn1VertConstraint: NSLayoutConstraint!

- when expanding widget, modify those constraints by code

bt2ToBtn1HorizConstraint.constant = 0
bt2ToBtn1VertConstraint.constant = 20

rather than arranging them with verticle constraints i want to replace the UI in collapsed mode with a table view in expanded mode. is that possible?


can the widget's UI be changed completely on pressing 'show more'?

You should try, I don't know if it is possible or not (there could be some side effect I don't know).


To do it, you need to

- remove the old views from their superview

- create a tableView with its content and the actions associated to each button

- add it to the superview


But, if I were you, I would try forst the simple approach with constraints, to see if this simple thing work.

If so, undertake the tableView option, a bit more complex.

If constraints does not work, understand what is the problem.