

NUI: style your iOS app with style sheets - jamesjyu
https://github.com/tombenner/nui

======
borgopants
A really interesting project which I feel might make web developers more
comfortable with iOS development.

As an iOS developer however, I find that using Interface Builder or pure code
is much more flexible and simpler to use than a CSS stylesheet.

------
wlue
A strategy that I found works really well to quickly style everything is to
create a category on UIView that defines a block property decorated with
UI_APPEARANCE_SELECTOR, then on the setter, invoke the block. Then set the
appearance proxy on app startup:

    
    
      [[UILabel appearance] setStyleBlock:^(id view) {
        UILabel *label = view;
        label.backgroundColor = [UIColor clearColor];
      }];
    

The advantage is that you can style properties that aren't supported by
UIAppearance natively, since a block just gets run when the view is ready to
be styled. You also can style subviews from the same block (ie. title label
inside of a warning view should be red and bold).

------
kreutz
Relevant: <http://www.pixate.com/>

~~~
pooriaazimi
I was very excited about Pixate when I followed your link, but after the
initial excitement it turned out that it's one of those stupid MVP
(potentially) vaporwares that's just a cute landing page with a form for "give
us your email so we can let you know when it's available" in the
signup/download link... It's a concept, not a product. And for all we know, it
could take a year or two before it's released. Yet, the landing page makes you
believe you can use it _today_ :

"Long gone are the days of tedious image slicing [..]. With Pixate, designers
and developers alike can conceive, [..]. etc., etc."

I really hate such "tricks". If it's a concept, just say so in the landing
page - we won't kill you! We _will_ find out in the end - it's hardly a
secret, and will be pissed when we click "Download SDK Now!" and find out it's
in the early stages of development...

I might've been interested in backing them up on KickStarter, but I really
don't trust them now (because of this trick they pulled on me). What if their
framework has a serious bug (a severe memory leak)? Can I trust these guys to
tell me so if I build my (imaginary) $50,000 app using their framework? No, I
don't feel that confident.

~~~
samnm
As someone who backed them on kickstarter I probably have a biased
perspective, but it seems to me that the product is coming along very nicely.
They are quite open to with the development of Pixate to backers. There is
also a Pixate demo app on the app store to see how it works on a device. Pity
they haven't been so open with nonbackers.

------
bengl3rt
I'm really glad this is open source. I intend to make use of it in any new
apps I start, and contribute back any bug fixes or improvements.

As it happens, I was going to build something like that for an app I'm due to
start tomorrow, but now I don't have to.

------
pdenya
I'd use something like this if it was built by apple but I can style apps
quickly enough as is without going out of my way to implement this.

As others have mentioned it's not really a "drop-in solution" and it doesn't
look to be much faster than just creating categories that return styled
objects you need eg: [UIButton greenButtonWithText:@"Sign up"]; [UILabel
headerLabelWithText:@"etc, etc"];

------
josephlord
Looks good I may use it. Looks like you are using the MIT license which is
nice and permissive but could I suggest that you leave the heading ("The MIT
License") in so that people can see at a glance that it is that.

That assumes that you haven't changed the licence at all.

[Edit: License does seem unchanged. I've sent a Pull request if the creator
does want to make this change.]

------
frankus
The Three20 guys tried something similar a few years back:
<http://three20.info/extension/extCSSStyle>.

It's a pretty neat concept, particularly if you have web content that needs to
be styled in coordination with your app's chrome.

------
jquave
Coincidentally I submitted a HN article earlier that included this on a list
of libraries.

HN discussion url: <http://news.ycombinator.com/item?id=4880974>

------
kyle_martin1
I REALLY want something like this. Like the others said, it must use
appearance proxies whenever possible. I literally want to add the source
files, edit the .nss file and it works.

------
supercoder
It's hardly a 'drop-in' solution if you have to change all your UI views to
inherit from the NUI equivalents.

I could never use this based on that requirement.

~~~
eclipxe
[NUIRenderer renderButton:myButton];

~~~
supercoder
Yeah that doesn't really make it drop-in either though does it.

The fact you have to litter you code with NUI references is a non-starter for
me.

They should have leveraged the UIApperance proxy. I know they have some reason
about gradients or something for not using it, but that shouldnt force a
compromise in the design.

~~~
shawn-butler
Can't speak for the author but UIAppearanceProxy is iOS 5.0+, also only a
subset of the UI classes respond to the UIAppearance protocol.

~~~
supercoder
Yeah, though targeting iOS 5 and up is really a non issue these days.

UIAppearance actually supports any property on any UIView, including your own
custom classes. The UI_APPEARANCE_SELECTOR declaration on the UIKit properties
is little more than for the purpose of documentation to make it clear what is
officially supported and tested for.

~~~
shawn-butler
Thanks for this info. So that means that UIAppearance is just some
implementation hack on KVC? That is very useful and very ugly at the same
time.

------
adelevie
I'd love to try this out with RubyMotion.

~~~
gry
Teacup is a RubyMotion-only stylesheet. <https://github.com/rubymotion/teacup>

~~~
DanielRibeiro
Don't forget Motion Layouts as well: <http://malkomalko.github.com/motion-
layouts/>

------
max81
Hm, I see NUI uses method swizzling, which in fact a potential reason for app
rejection.

------
dia123
Wow super cool - i wonder if it works with ruby motion? I don't know why it
wouldn't.

------
chrismetcalf
Anybody tried it with RubyMotion yet?

