"We all love Paul Hegarty" Stanford IOS8 public class personal note drawing drawing, Uicolor color, fonts font

Source: Internet
Author: User
Tags call back

The last word describes some of the basic principles of view drawing, which continues to unfold. Uibezierpath can draw lots of interesting graphics.


Using different constructors, such as Roundedrect, are four rounded rectangles, or simply ellipses and circles. You can even cut any path, cut using the Addclip method, and after clipping you can manipulate this part of the cut, for example, if you are drawing a card with a small fillet effect, you can draw the card into a rectangle and cut it into a smaller fillet matrix. , so that the corners are rounded. This is the simplest way to get a rounded card.

You can also perform collision detection, which is based on the circle rules.

Now let's talk about the color problem.


You can use the system to give the standard colors, such as red, green, you can also color, and you can set your colors as a mode, so you use the color is actually used a graphic, this is cool.

You can set the background color for the view, the color can also have transparency, the transparency (Alpha) uses the range 0-1.0 is fully transparent and 1 is completely opaque. You can use method colorwithalphacomponent to create a translucent color.

If you use transparency when drawing, you need to tell the system to set the UIView opaque property to False. Why did you do it? Because transparency is very expensive to draw, because the view behind you is displayed, the system must mix the overlapping views to draw, which is very expensive in the image processing power. So if it is not necessary to do so, if you do not set this property to False when you draw, then you will not be successful in the shape of translucent drawing.

You can set the entire view to translucent because it has an Alpha property on its own.


What happens when a view with transparency is superimposed on each other? They are mixed, the first child view in the sub-view array appears in the last face, and the remaining sub-views appear in the order of the preceding ones. You can completely hide a view and only need to set its hidden property, this kind of hidden view is very common, and then appears on the screen when a condition is reached. The hidden view will not be drawn, nor will it accept any touch events, but it still exists in the hierarchical relationship of the view as if it were waiting there.


Usually we use Uilabel to draw text on the screen, if you want to draw on your drawrect, you use nsattributedstring to do this work, it has a lot of properties can be set


These properties are in the dictionary format, and the range is Nsrange format, not the range format, which is an ancient format.

Here's a look at the font (Fonts)


Fonts start with IOS7, including IOS8. Proper use is important, and they are the key to creating beautiful UIs.


So how to do beautiful fonts, we use Preferredfontfortextstyle, font style is similar to the title or text, as if we use Word, iOS can also set the format of the font, it has some prepared format. With the recommended self always good, it contains the format and size, you can change its size. Of course you can also create a font yourself.

There are some system default fonts, such as buttons or the paragraph controller on the font, you do not always use the default bar? It is a better plan to recommend it with the system.

So how do we show the image? We have a uiimageview that shows pictures, but you may want to throw your pictures into the drawrect.


In general you will create a picture with a name in order to get it out of the images.xcassets.


Once you have this picture, you can send a message to show it, this method is Drawatpoint, then the system will put the normal size of the picture in the upper left corner of the point.

You can also use the Drawinrect method, which will scale the image in this rectangular area.

Or, as we said before, with Drawaspatterninrect, it will tile until it is covered in the area.


So what happens when your boundaries change, like when you spin your cell phone and tall into Humpty Dumpty, you might want to call back again, but that's not going to work, and your image will be flattened, so you generally don't get the result you want. However, this is the default practice, stretching the image for better performance. You can control how the boundary changes when you manage it yourself. Use the Contentmode in the view to do so. One strategy is to not change the picture, but to move your picture to the new boundary in all directions.

Another way to do this is to scale the image with the width and height of the original images.

You can also use the redraw you most want to use.

"We all love Paul Hegarty" Stanford IOS8 public class personal note drawing drawing, Uicolor color, fonts font

Related Article

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.