Pegasus

What is Pegasus?

Pegasus is a lightweight open-source framework that allows you to build user interfaces for your Cocoa Touch projects in XML.

You can grab Pegasus from GitHub here.

Why would I want to build my interface in Pegasus?

If any of these are true…

  • You come from a web development background and prefer to design interfaces in markup.
  • You can’t stand the Interface Builder workflow.
  • Your app needs to create UIs on-the-fly at runtime (for example, downloaded from a web server).
  • You’re a designer, or have a lot of designers on your team, who you want to have design UIs without programming experience.
  • You want to create a common UI that scales on both the iPhone and iPad screens.
  • You’re not comfortable writing your own UI programmatically, or just find it too much work.
  • You’re just looking for a simpler, quicker and more intuitive way to quickly build UIs.

…then Pegasus may just be perfect for you. It’ll save you a lot of work, too!

For example, if you wanted to create a simple UIView which contains a UIImageView, UITextField and UIButton, here’s what it looks like in Objective-C:

        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]];
        imageView.frame = CGRectMake(10, 100, 300, 50);
        [view addSubview:imageView];
        UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(40, 300, 240, 40)];
        textField.placeholder = @"Enter text";
        [view addSubview:textField];
        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(100, 400, 20, 40)];
        [button setTitle:@"OK" forState:UIControlStateNormal];
        [view addSubview:button];

I’ve even been fairly conservative and tried to use compound statements where possible, and the code is still fairly unwieldy and difficult to read. These issues are exacerbated when dealing with a multi-level view hierarchy where it can become extremely difficult to refactor the view.

Instead, the same view could be built in Pegasus as follows:

<LinearLayout frame="fill_parent" padding="10">
	<ImageView height="300" width="50" image="image.png" />
	<TextField height="240" width="40" placeholder="Enter text" />
	<Button height="20" width="40" title="OK" />
</LinearLayout>

It really is as simple as specifying each view as a tag and nesting tags to specify subviews. Each XML corresponds to a UIKit property. Almost all properties are supported, and Pegasus even includes additional totally awesome features that will improve your coding experience:-

Layouts can be deployed which automatically lay out your views at runtime, meaning that you don’t need to individually position each view.

Translators are used by Pegasus to translate your string attribute values into their corresponding UIKit structs/enums/primitives/objects. For example, the string "{{0,0}, {320, 460}}" needs to be translated into its CGRect equivalent. But while I was coding that, I decided to add some treats here. For example, for UIColor you can now specify any preset color name (e.g. "blue", "green", …) or even a hex value just like you would in HTML (e.g. "#ff00cc")!

Virtual Properties can be used where a class doesn’t quite provide the property that you want, so I created some “virtual” properties to add that missing functionality. For example, to set a UIButton‘s title, you should be using setTitle:forState: which can’t be set using a property. But given that most people just want to set a title for UIControlStateNormal, I created a virtual property called “title” which overrides the default Pegasus attribute-to-property mapping and calls the relevant method for you.

For further information, please consult the Pegasus wiki.

167 Responses to “Pegasus”

  1. Lino says:

    What’s up, for all time i used to check webpage posts here early in the break of day, since i love to learn more and more.

    My website – music marketing press promotion distribution and retail reviews (Lino)

  2. Mari says:

    Good post. I learn something totally new and challenging on websites I stumbleupon on a daily
    basis. It’s always interesting to read content from other writers and practice a little something from their websites.
    psychology bristol university (przestrzentransformacji.com) polski psycholog londyn

  3. Rob says:

    hi!,I really like your writing so so much! share we keep up a correspondence more
    about your article on AOL? I require an expert on this house to solve my problem.
    Maybe that’s you! Looking ahead to see you.

    my web site – Breast Actives

  4. Eleanor says:

    Excellent blog here! Additionally your site loads up very fast!

    What web host are you the use of? Can I get
    your associate hyperlink in your host? I wish my web site loaded up as fast as yours lol

    Stop by my web site :: watches luxury replica (ihaunter.com)

  5. Rachele says:

    Create custom labels to give wine as a holiday gift.
    There is a text box lined up with the blank note so that you can type a message directly onto it.
    Purchase or design your own tasting cards that record the type
    of wine, the vineyard, and the year it was produced.

    Here is my web blog wine and design corning ny (Rachele)

  6. Tresa says:

    It’s very trouble-free to find out any matter on web
    as compared to textbooks, as I found this paragraph at this web page.

    My web site web hosting reviews 2011 pcmag

  7. Coral says:

    Were you in great health like a kid? Do you remember
    everything you were eating and drinking? Do you have a great diet today?
    You possibly will not obtain the nutrients that
    are required now. By utilizing vitamins, use these tips to feel great.

    There exists a process to the body to execute before you decide to experience the outcomes of vitamins.

    This makes it imperative that you understand some great benefits of each, and also
    the way that they work along with others. Its absorption is inhibited by calcium, though
    iron is absorbed well with Vit C. It’s a great idea to drink some
    orange juice with the iron supplement while avoiding antacids and dairy food
    for at thirty minutes after taking iron.

    Never forget about the product warnings on vitamin levels.

    Vitamin and supplements can have serious adverse reactions when
    taken with prescription and non-prescription medicines.
    In case you have high blood pressure levels or take heart medications, Ginseng can be very dangerous.

    When you have a tomato allergy, Lycopene could
    be deadly. Before taking any vitamins or supplements, always see the warning labels or ask your pharmacist or doctor.

    Are you currently having problems together with your
    vision recently or just are worried with
    maintaining the healthiness of your eyesight? Try taking vitamins such as
    Omega-3, E and C and Zink. Not only do these help promote good eye
    care, in addition they help in other aspects of maintaining a wholesome lifestyle.

    Some vitamins might be stored at room temperature, you
    should store oil-based and gummy vitamins in the refrigerator.
    They might become sticky and clump together if you fail
    to do this. Since you will find no definitive way to break them apart, this
    would render the whole bottle useless.

    As adults, everyone knows how important vitamins and minerals will
    be to our diets but what about our little ones? Inspite of the
    energy they generally have, they can be burning away what the body demands to enhance health and combat infection.
    Make sure to give your youngster vitamins to ensure these to maintain good health through
    the growing years.

    Some vitamins are stored in the body, among
    others will not be. Water-soluable vitamins dissolve inside the fluids in the
    body and they are flushed out regularly. These vitamins include B vitamins and vitamin C.
    It is very important consume these vitamins each day, since
    these vitamins usually are not stored within your body.

    When choosing vitamins, always check the expiration date around the package
    prior to buying them. Vitamins use a life expectancy and never last forever.
    Storage time, contact with light and temperature can all effect the quality of vitamins and additional
    decrease the expiration date. So, make sure that you are purchasing quality vitamins which may have not expired.

    Have you seen that despite exercising, taking your bodybuilding supplements and maintaining a healthy diet that you simply usually become ill with greater frequency
    than the others who don’t break their back to promote a healthy body?
    Try adding a lot of the essential vitamins to the supplement doses.
    You are burning far more fuel than the others thus more deficient in these
    nutritional supplements so you have to consume a lot more than
    the average person.

    Will not take vitamins because somebody you know is pressuring you to achieve this.
    Many people are not a similar, which means that the things that
    work for starters person could possibly have an entirely different influence on another.
    You should speak to your doctor to see what he would suggest if you are worried about the body lacking vitamins.

    If you are intending a surgery, let your doctor know any and all health supplements
    you are taking. , and herbs can all have
    negative effects in your upcoming surgery.nutritional supplements It is recommended to stop taking all
    supplements no less than 2 weeks prior to surgery to protect yourself from any dangerous complications.

    Try adding a multi-vitamin to your regular routine when you are finding it difficulty to have the fruit and vegetable nutrition you will need every single day.
    There are many great muti-vitamin choices for all ages, activity levels and medical conditions.
    You may get the nutrition you need even when you don’t eat right.

    Whenever a supplement carries a recommended daily allowance amount
    listed, don’t exceed it! Shop around and see what the consequences are of taking an excessive amount of that product.
    So don’t take an overdose lightly just since it is a vitamin, it might be sleep disturbances or
    even heart rhythm disturbances!

    Don’t take vitamins if you are currently pregnant before you discuss it together with your doctor.
    Vitamins tend not to appear to be they would cause any harm,
    but one never knows. Don’t let your kids be harmed through your ignorance.

    It’s now time to be healthy. Everything you have read
    are some superb advice, but you can find out more. The more information you possess,
    the higher your wellbeing will be along with the longer you will probably live, so tend
    not to let your fact-finding mission end here!

    Take a look at my web blog … http://adelgaza20.com

  8. Minnie says:

    It’s awesome to go to see this web page and reading the views of all friends
    on the topic of this post, while I am also eager of getting familiarity.

    Feel free to surf to my homepage – plants vs zombies garden warfare download

  9. Kevin says:

    Everyone loves it when folks get together and share thoughts.
    Great blog, stick with it!

    my blog :: cheats boom beach

  10. Michale says:

    It’s actually a great and helpful piece of info. I’m satisfied
    that you shared this useful information with us. Please stay us informed like this.

    Thanks for sharing.

    My blog post … rey arturo

  11. Tasha says:

    This is really interesting, You’re an overly professional blogger.
    I have joined your feed and look ahead to in quest of extra of your excellent post.
    Also, I’ve shared your web site in my social networks

    My blog – Télécharger Cristeros Film

  12. Fidel says:

    Because the admin of this website is working, no uncertainty very soon it will be famous, due to its
    feature contents.

    Look at my web site download Dead Rising 3

  13. Muhammad says:

    This decreases the risk of investment as you
    test the waters and see if Facebook contests can be beneficial to
    your business. Implement multi-factor authentication technologies like smartcards.
    Hiking can also have the added benefit of being a good stress reliever.

    My site; fbh tool

  14. Sherlene says:

    Hey I know this is off topic but I was wondering
    if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates.
    I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with
    something like this. Please let me know if you run into anything.
    I truly enjoy reading your blog and I look forward to your new
    updates.

    Stop by my weblog – the sims freeplay hobbies fashion

  15. Betsy says:

    Hello friends, fastidious paragraph and pleasant arguments commented at this place,
    I am really enjoying by these.

    My web-site – cash now

  16. Nichol says:

    Bitcoin also has the advantage of being used on an international
    level. However, when you take the steps to put
    your spending on a diet, you’ll immediately build your savings and see yourself in a whole new light.
    Today they released their 2014 Threat Predictions, and here’s
    what they believe will be in store for us:. arrest on a young Bitcoin website owner,
    exposing a deep web of drugs, guns, prostitution, murder
    for hire and a ready tool for tax evasion and money laundering.

    Here is my weblog; earn bitcoins free online (http://www.Silverhoarders.com)

  17. Josephine says:

    Piece of writing writing is also a excitement, if you know then you can write or
    else it is complex to write.

    Stop by my web blog double eyelid surgery (cnn.com)

Leave a Reply