[Extraordinary programmer]uikit Handwriting controls Uiimageview and UITableView

Source: Internet
Author: User

Uiimageview is used to place pictures.

Created? There are five kinds of Uiimageview objects? Method:
1.UIImageView *imageview1 = [[Uiimageview alloc] init]; Instantiated an object of type Uiimageview
2. Uiimageview *imageview2 = [[Uiimageview alloc] initWithFrame: (CGRect)]; Instantiates an object of type Uiimageview and sets the position of the picture at the same time
3.UIImageView *IMAGEVIEW3 = [[Uiimageview alloc] Initwithimage: (UIImage *)]; Instantiates an object of type Uiimageview also sets which picture object is the picture

Not used
1. Uiimageview *imageview4 = [[Uiimageview alloc] Initwithimage: (UIImage *) Highlightedimage: (UIImage *)]; When this ImageView highlighted attribute is yes, the parameter highlightedimage is highlighted, and the first parameter is normally displayed UIImage
2. Uiimageview *imageview5 = [[Uiimageview alloc] Initwithcoder: (Nscoder *)];

When you want to change the position later, you can reset the Frame property:
Imageview.frame = CGRectMake (CGFloat x, cgfloat y, cgfloat width, cgfloat heigth);
Notice that Uiimageview also has a bounds attribute:
Imageview.bounds = CGRectMake (CGFloat x, cgfloat y, cgfloat width, cgfloat heigth);

frame sets its position and size, and bounds can only set its size, and the X and y in its parameters do not work even if the frame property was not previously set, the final position of the control is not the parameter set by the bounds. The bounds implementation is to scale the Uiimageview control to the center of the original center.
For example, the following code:
Imageview.frame = CGRectMake (0, 0, 100, 460), imageview.bounds =
CGRectMake (100,, 160, 230); After execution, this The position and size of a imageview are (80, 115, 160, 230).

contentmode Property:
This property is used to set the way the picture is displayed, such as centering, right, scaling, etc., the following constants are available:
uiviewcontentmodescaletofill 
Uiviewcontentmodescaleaspectfit
uiviewcontentmodescaleaspectfill 
uiviewcontentmoderedraw 
uiviewcontentmodecenter 
uiviewcontentmodetop 
Uiviewcontentmodebottom
uiviewcontentmodeleft 
uiviewcontentmoderight 
Uiviewcontentmodetopleft
uiviewcontentmodetopright 
uiviewcontentmodebottomleft 
Uiviewcontentmodebottomright

Change location:
Change the position of a uiimageview to modify its frame property directly
To modify its center properties:
Imageview.center = Cgpointmake (CGFloat x, cgfloat y); The Center property refers to the middle point of the ImageView.
Using the Transform Property
Imageview.transform = cgaffinetransformmaketranslation (cgfloat dx, cgfloat dy); where dx and dy indicate how much you want to move in the X or Y direction, rather than how much to move.

To rotate an image:
Imageview.transform = cgaffinetransformmakerotation (cgfloat angle);
Notice that it rotates in a clockwise direction, and that the center of rotation is the center of the original ImageView,
The location of the Center property sheet.
The parameters of this angle are in radians, not in our most commonly used degrees, so you can write a
A macro definition:
#define Degreestoradians (x) (m_pi* (x)/180.0) where x writes the angle to rotate

To scale an image:
Or use the Transform property:
Imageview.transform = Cgaffinetransformmakescale (cgfloat scale_w, CGFloat scale_h);
Among them, CGFloat Scale_w and cgfloat scale_h respectively table? Scale the original width and height to how many times

Play? Series Pictures:
Imageview.animationimages = Imagesarray; Set the number of seconds that all pictures are played imageview.animationduration = [Imagesarray count]; Do not repeat how many times, 0 means countless times imageview.animationrepeatcount = 0; Start playing [ImageView startanimating];

To add a click event to a Picture:
imageview.userinteractionenabled = YES; UITapGestureRecognizer *singletap = [[UITapGestureRecognizer alloc] initwithtarget:self action: @selector ( Tapimageview:)]; [ImageView Addgesturerecognizer:singletap]; Be sure to set userinteractionenabled to Yes before you can respond to the click event.

Other settings:
Imageview.hidden = yes or no; Hide or Show picture Imageview.alpha = (cgfloat) al; Set Transparency Imageview.highlightedimage = (UIImage *) hightlightedimage; Imageview.image = (UIImage *) image when setting the light display image; Set the normal display picture [ImageView SizeToFit]; Resize the diagram to be the same as the content picture

The difference between UIButton and Uiimageview:
1> Uiimageview can only be one image (the image will be populated by default for the entire Uiimageview) Image\setimage:
2> UIButton can display 2 kinds of pictures
Background (the background fills the entire UIButton) Setbackroungimage:forstate:
Front (the picture that covers above the background, according to the previous size) Setimage:forstate: * can also display the text

1> Uiimageview Default is not responding to click events
2> UIButton can respond to click events: addTarget:action:forControlEvents:

1> Uiimageview: Only show pictures, do not listen to click, click on the picture after not do any reaction
2> UIButton: Display the picture, listen to the click, click on the picture and do some other things

1> UIButton is able to add listeners to listen to events because it inherits from Uicontrol
2> Uiimageview cannot add listeners to listen to events because it inherits directly from UIView

UITableView

Almost all iOS projects can see the shadow of UITableView, UITableView is more commonly used in the iphone, the more control. It is mainly used to display data for a series of tables.
Features: Displays a list of large content, single-row, multi-column, vertical scrolling, no horizontal scrolling, a large number of datasets, and powerful performance.
UITableView has two default built-in styles one is concise style uitableviewstyleplain. The other is the group style uitableviewstylegrouped

UITableView have two agency agreements?
Protocol Uitableviewdatasource:? To provide data to TableView
What is data source: where is the source of the information? In the case we will set this uiviewcontroller to have UITableView for his datasource.
Protocal uitableviewdelegate: Controlling the way TableView is displayed and incident response

Protocol implementation:

// Setting the height of a partition -(nsstring*) TableView: (uitableview*) TableView : titleforheaderinsection : (nsinteger) section

// Change the height of a row
-(CGFloat) TableView: (UITableView *) TableView heightforrowatindexpath: (Nsindexpath *) Indexpath

// Line Indent
-(Nsinteger) TableView: (UITableView *) TableView indentationlevelforrowatindexpath: ( Nsindexpath *) Indexpath


[Extraordinary programmer]uikit Handwriting controls Uiimageview and UITableView

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.