IOS Learning Record

Source: Internet
Author: User

    • Expression arrangement
mjviewcontroller.m//01-Emoji////Created by Apple on 13-11-24.//Copyright (c) 2013 itcast. All rights reserved.//#import "MJViewController.h"/* 1.adjust .... method to remove the 2nd parameter----add: (BOOL) Add (Cannot add global variable or member variable) 2. Add a "+" button to the end of the expression, adding a button to add an emoticon (emoticon image random) */#define KIMGWH 50#define Kinitcount 13@interface Mjviewcontroller () @end @implementation Mjviewcontroller#pragma Mark Controller's view is loaded once-(void)        viewdidload {[Super viewdidload]; [Self adjustimageposwithcolumns:2 add:yes];} #pragma mark to adjust the position of the picture-(void) Adjustimageposwithcolumns: (int) columns add: (BOOL) Add {//1. Define number of columns, spacing//3 columns per row//#warning varies    Sample//int columns = 3; spacing between each expression = (Controller view width-Number of columns * expression width)/(Number of columns + 1) cgfloat margin = (Self.view.frame.size.width-columns * Kimgwh)/        (columns + 1);    2. Define the position of the first expression//the Y-value of the first expression cgfloat Oney = 100;        The first expression x value cgfloat OneX = margin;        3. Create all emoticons for (int i = 0; i < Kinitcount; i++) {//I this position corresponds to the number of columns int col = i% columns; I ThisThe number of rows corresponding to an int row = I/columns;        The number of columns (COL) determines x cgfloat x = OneX + col * (Kimgwh + margin);        The number of rows (row) determines y cgfloat y = oney + row * (Kimgwh + margin); #warning not the same if (add) {//Add new ImageView int no = i% 9;//no = [0, 8] nsstring *imgname            = [NSString stringwithformat:@ "01%d.png", no];        [Self addimg:imgname x:x y:y];            } else {//Remove the old ImageView settings x, y//Take out the corresponding ImageView for the i + 1 position, set X, Y value//+ 1 to skip the front Uisegmentcontrol            UIView *child = self.view.subviews[i + 1];            Remove frame CGRect Tempf = child.frame;            Modify x, y Tempf.origin = Cgpointmake (x, y);        Re-assignment child.frame = Tempf; }}} #pragma mark add emoji icon: Emoji image name-(void) Addimg: (NSString *) icon x: (cgfloat) x y: (cgfloat) y {uiimageview *one = [[UII    Mageview alloc] init];    One.image = [UIImage Imagenamed:icon]; One.frame = CGRectMake (x, Y, Kimgwh, KIMGWH); [Self.view Addsubview:one];}    #pragma mark to change the number of columns of the expression-(ibaction) Indexchange: (Uisegmentedcontrol *) Sender {[UIView beginanimations:nil context:nil];        [UIView setanimationduration:0.5];    int columns = Sender.selectedsegmentindex + 2;        [Self adjustimageposwithcolumns:columns add:no]; [UIView commitanimations];} @end

  

IOS Learning Record

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.