iOS randomly changes background color and displays numbers

Source: Internet
Author: User

Attached code, similar to the verification Code on the registration website

Shantu:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/71/81/wKioL1XSz7iRuETxAAA3hZbJwgo878.jpg "style=" float: none; "title=" screenshot 2015-08-18 pm 2.13.31.png "alt=" Wkiol1xsz7iruetxaaa3hzbjwgo878.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/71/84/wKiom1XSza3R2sPyAAA-To6Ogsk260.jpg "style=" float: none; "title=" screenshot 2015-08-18 pm 2.13.38.png "alt=" Wkiom1xsza3r2spyaaa-to6ogsk260.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/71/81/wKioL1XSz7nBbRN5AABOBqoX_tE616.jpg "style=" float: none; "title=" screenshot 2015-08-18 pm 2.13.48.png "alt=" Wkiol1xsz7nbbrn5aabobqox_te616.jpg "/>

-(void) change

{

    Self.Changearray = [[Nsarray Alloc] initwithobjects:@ "0",@ "1",@ "2",@ "3",@ "4",@ "5",@ "6",@ "7",@ "8",@ "9",@ "A",@ "B",@ "C",@ "D",@ "E",@ "F",@ "G",@ "H",@ "I",@ "J",@ "K",@ "L",@ "M",@ "N",@ "O",@ "P",@ "Q",@ "R",@ "S",@ "T",@ "U",@ "V",@ "W",@ "X",@ "Y",@ "Z",@ "a",@ "B",@ "C",@ "D",@ "E",@ "F",@ "G",@ "H",@ "I",@ "J",@ "K",@ "L",@ "M",@ "n",@ "O",@ "P",@ "Q",@ "R",@ "S",@ "T",@ "U",@ "V",@ "W",@ "x",@ "Y",@ "Z",Nil];

nsmutablestring *getstr = [[nsmutablestring alloc] C7>initwithcapacity:5];

self. changestring = [[nsmutablestring alloc] initwithcapacity : 6 ];

for (nsinteger i = 0; i < 4; i++)

{

nsinteger index = arc4random()% ([self. changearray Count]- 1);

getstr = [self. Changearray objectatindex: index];

self. changestring = (nsmutablestring *) [self. changestring stringbyappendingstring: getstr];

}

}


-(void) DrawRect: ( CGRect ) Rect {

[super drawrect: rect];

float red = arc4random()% / 10 0.0;

float green = arc4random()% / 100.0;

float blue = arc4random()% / 100 .0;

uicolor *color = [uicolor colorwithred: Red Green : Green Blue: Blue Alpha:1.0];

[ self setbackgroundcolor: color];

nsstring *text = [nsstring stringwithformat:@ "% @ ",self. changestring ];

cgsize cSize = [@ "S" sizewithfont: [ Uifont systemfontofsize:[]];

int width = rect. size . width /text. length -CSize. width ;

int height = rect. size . Height -CSize. Height ;

cgpoint point ;

float PX, PY;

for (int i = 0; i < text. length ; i++)

{

NSLog(@ "Rect.size.width/text.length * i%f", rect. ) size . width /text. length * i);

PX = Arc4random ()% width + rect. size . width /text. length * i;

PY = Arc4random ()% height;

Point = Cgpointmake (PX, PY);

Unichar c = [text characteratindex: i];

nsstring *textc = [nsstring stringwithformat:@ " %c ", C];

[textc drawatpoint:p oint withfont: [uifont systemfontofsize:[]];

}

cgcontextref context = uigraphicsgetcurrentcontext();

cgcontextsetlinewidth(context, 1.0);

for(int cout = 0; cout < 10 ; cout++) {

red = Arc4random () % - / 100.0 ;

green = Arc4random () % - / 100.0 ;

Blue = Arc4random () % - / 100.0 ;

color = [uicolor colorwithred: Red Green: Green B Lue: Blue Alpha:1.0];

cgcontextsetstrokecolorwithcolor(context, [color cgcolor]);

PX = Arc4random ()% (int) rect. size . width ;

PY = Arc4random ()% (int) rect. size . Height ;

cgcontextmovetopoint(context, PX, PY);

PX = Arc4random ()% (int) rect. size . width ;

PY = Arc4random ()% (int) rect. size . Height ;

cgcontextaddlinetopoint(context, PX, PY);

cgcontextstrokepath(context);

}

}


iOS randomly changes background color and displays numbers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.