Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

repeat background image

I have create a view:

var justifyLabelview = Ti.UI.createView({
    backgroundImage: "images/black_dot.png"
});

is it possible to repeat the background image as we can do in CSS?

background-repeat: repeat-x;
— asked October 14th 2010 by Borey Lim
  • view
  • view backgroundimage
0 Comments

7 Answers

  • I've managed to add it like this:

    Open up TiUiView.m in your mobilesdk folder and add the following before @end

    -(void)setRepeatedBackgroundImage_:(id)image
    {
      NSURL *bgURL = [TiUtils toURL:image proxy:proxy];
      UIImage *resultImage = [[ImageLoader sharedLoader] loadImmediateImage:bgURL];
      self.backgroundColor = [UIColor colorWithPatternImage:resultImage];
    }
    

    And use it in your project like so:

    Ti.UI.createView({repeatedBackgroundImage:'something.png'});
    
    — answered April 28th 2011 by Jeroen Kntl
    permalink
    10 Comments
    • Nice fix!

      — commented April 28th 2011 by Tim Holt
    • I don't know why but it doesn't work for me…

      — commented May 4th 2011 by Florent Crivello
    • Um, where exactly is this mobilesdk folder? I have searched the Titanium folder (Program files/Titanium Developer) and android sdk for the file TiUiView.m without any results..

      — commented May 19th 2011 by Adam Smith
    • Hmm… I added the code to the TiUIView.m and attempted to create a view. No errors, but nothing happens. Do you have to "recompile" the sdk or anything after adding to the .m file?

      — commented June 16th 2011 by Seth Davis
    • I'm also not getting the desired effect, using 1.7.1

      — commented July 14th 2011 by Tony Lukasavage
    • Oops, nevermind, I got it working now. Great tip!

      — commented July 14th 2011 by Tony Lukasavage
    • Nice! What about Android? :)

      — commented September 12th 2011 by John Johnson
    • an android workout around would be great.

      — commented November 30th 2011 by dev 1605
    • it's unclear for me too. Can't find the TiUiView.m file. Recompile? How?

      thanks

      — commented December 20th 2011 by Arjan Brinkman
    • @tony want to do same for Android but unable to locate this file. I am using Ubuntu for development. Any help where can i find this file..

      — commented January 31st 2012 by Sahil Grover
  • In SDK 1.8.1 (beta) you can add 'backgroundRepeat: true' to a view and it will tile the background image.

    As of this date, it is not yet implemented for Android. Watch http://jira.appcelerator.org/browse/TIMOB-6586.

    — answered January 29th 2012 by Mark Ruys
    permalink
    1 Comment
    • does tile in every direction or only vertical? (for example, what if image is narrow than the screen size)

      — commented February 18th 2012 by Tobias O.
  • use this

    backgroundRepeat : true
    
    — answered January 10th 2013 by Mohsin Rasheed
    permalink
    0 Comments
  • nice, i'll ask platform team to add this to 1.8 consideration timeline.!

    — answered July 15th 2011 by Jeff Haynie
    permalink
    4 Comments
    • Yes this would be a great feature to have built in, please do it! :)

      — commented July 20th 2011 by Marc Wickens
    • backgroundRepeat is only supported for iOS in 2.0.1GA2. Is there any plans to support this in Android?

      — commented May 13th 2012 by Siva Kanesh
    • Sorry my mistake, it does work in Android, but the IntelliSense lists only iPhone and iPad as the supported platforms.

      — commented May 13th 2012 by Siva Kanesh
    • @Titanium team thanks a lt for adding this feature. Hope u guys add shadow, border-radius-top-left border-radius-top-right border-radius-bottom-left border-radius-top-right things as well soon :)

      — commented May 16th 2012 by Sahil Grover
  • I've been unable to get this working. Any word on it being a built in thing?

    — answered October 13th 2011 by Digital Surgeons
    permalink
    0 Comments
  • Does anyone know if this has been added or not recently?

    — answered December 2nd 2011 by Benjamin Morrison
    permalink
    0 Comments
  • Don't know if this question needs any answering, but from 2.1.x version 'backgroundRepeat' property is available for both android and iphone

    — answered November 7th 2012 by Shalvika Sood
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.