Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Styling subviews (children) #90

Closed
KamilLelonek opened this issue Aug 3, 2014 · 6 comments
Closed

Styling subviews (children) #90

KamilLelonek opened this issue Aug 3, 2014 · 6 comments

Comments

@KamilLelonek
Copy link

I have a view controller that contains a couple of subviews (UIView). While I can apply style for UIViewController, I'd like to have separated stylesheets for these subviews and just append these views already styled. How can I achieve that?

The problem is to decouple stylesheets from ViewController and provide them with custom views. Is there any way to do that?

@GantMan
Copy link
Member

GantMan commented Aug 3, 2014

Let me rephrase to see if I've understood. You have some subviews that are not anchored to a particular controller, and you'd like a centralized location to style these and apply them when you place these styled subviews?

Universal styles can be found in the Application stylesheet (stylesheets/application_stylesheet.rb). It's a great spot to include any universal styles. Then when you add the views they'll have access to those styles.

Would that be what you need?

@KamilLelonek
Copy link
Author

Hi, thanks for your response.

My case is as follows:

I have a container view, which contains a couple of views. These views are swipeable so at one time only one is visible. I have also tab bar which allows me to change view on tab click. I'd like to have these views separate from each others so that each of them implements its own stylesheet. I want to just append in my controller a subview as a class of this particular custom view without knowing about its inner structure and styles.

Another example:

I have a validable input (UITextField), e.g. email or phone number. This input should responds to changes and style itself different depending on provided input (change color, font, border). I want to append just ValidableEmailTextField and don't bother about its inner styles.

The last one to be clear enough:

In my controller I allow user to either input friend's email or choose it from contacts list. I want to build that interface by appending just two views: ValidableEmailTextField and FriendsListTableView. My controller's stylesheet should only place list container under input and nothing more. Both text field and table view should come with their own styles and my controller shouldn't know about them at all.

TL;DR
I need to have reusable components extending UIView with own styles and include them without knowing about their stylesheets.

@squidpunch
Copy link
Contributor

For what it is worth. The way I have been doing this on a project of mine is creating a structure like this:

app/controllers/example_controller.rb

  def viewDidLoad
    super
    rmq.stylesheet = ExampleStylesheet
  end

app/stylesheets/controller_stylesheet.rb

class ExampleControllerStylesheet < ApplicationStylesheet
  include SharableItemStylesheet

app/stylesheets/sharable_item_stylesheet.rb

module SharableItemStylesheet
  # shared view items
end

this allows for me to create shareable objects with their own defined styles and enclosed in a stylesheet for the control. I think thats what you were asking for. The drawback is you have to include the stylesheets into the controller that is using them - etc.

would be interesting in reading a different option if one exists.

@KamilLelonek
Copy link
Author

I see. I found this solution in docs too. It seems this is the only way to do that.

@GantMan
Copy link
Member

GantMan commented Aug 3, 2014

As for the validatable text fields that should change styles, we've got EXACTLY that brewing for the 0.7 release. If you pull down the RMQ app, you'll see a nice example (super awesome thanks to @squidpunch for the progress he's made). Check out the code: example image attached here:

image

I know if the style is set, and you could call "reapply_styles" this should work nicely. Maybe your subviews can have their style already set (not sure on the exact situation without code). As for now it only remembers the last style. But I know @twerth is looking at fixing styles to maintain history.

@twerth
Copy link
Member

twerth commented Aug 4, 2014

FYI, rmq's generators will create these things for you:

rmq create view example_view
rmq create table_view_controller example_table
rmq create collection_view_controller example_collection

@twerth twerth closed this as completed Aug 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants