Self-learning iOS – thirty days thirty Swift projects

Self-learning iOS - thirty days thirty Swift projects

The whole plan is completely self #30daysSwift inspired by Sam Lu, in his 100 days Swift wrote 40 small projects, I was watching him in January 5th from a Medium article immediately after the decision to begin a 30 day self-study program yourself, write a small program every day, one day if not written also on the weekends to write a few up. Because in fact, the basic grammar of Swift and do not know too much, I was looking at the basic grammar and side of a pile of Google on the network or Swift tutorial video to do the project.

Sam Lu did not put their project code open out, but I still want to try the open source, can give those people a little bit is Swift beginners “Enlightenment”, because it is precisely because of “open source spirit”, the Internet will have many “tutorial”, the following is the 30 small projects Github link:


Project 1 – Simple Stop Watch

Self-learning iOS - thirty days thirty Swift projects

1) NSTimer to do the timer: NSTimer.scheduledTimerWithTimeInterval;

2) start, pause and restart the three functions;

Project 2 – Custom Font

Self-learning iOS - thirty days thirty Swift projects

1 see @dingyi) said on Twitter, “making workshop” currently authorized individuals free for non commercial use, so made a donation of 1 yuan, down 3 fonts used to do the test, are making workshop Jin black, to the dark and childlike innocence;

2 drag the font file.Ttf or.Otf to the project, configure Info.plist – Fonts by application, and then in the Build Phases – Copy Bundle Resources font;

3) need to use the following tips to quickly find a FamilyName, can be found after the use of Code can be deleted:

For family in (UIFont.familyNames) {
for font in UIFont.fontNamesForFamilyName (family) {print (font)}}

Project 3 – Play Video Local

Self-learning iOS - thirty days thirty Swift projects

1) import AVKit and AVFondation, you can use the system video player;

2) with the font Project 2, like, if you want to see the video in iPhone build, then you also need to add Copy Bundle Resources video resources, so on the line;

3) review the use of UITableView and UITableViewCell by the way;

Project 4 – Snapchat Menu & Camera

Self-learning iOS - thirty days thirty Swift projects

1) Snapchat three screen paddling is very classic, use UIScrollView to achieve the three screen motion, the definition of 3 ViewController;

2) left and right is actually a Snapchat interface screenshot ImageView, ha ha, so the Status Bar to hide, UIApplication.sharedApplication ().StatusBarHidden=true;

3) CameraView part of a small complex, used in the UIImagePickerControllerDelegate API? (don’t know what to call)

Var captureSession: AVCaptureSession? Var stillImageOutput: AVCaptureStillImageOutput? Var previewLayer: AVCaptureVideoPreviewLayer?

Project 5 – Carousel Effect

Self-learning iOS - thirty days thirty Swift projects

1) photo cross screen paddling carousel effect, using UICollectionViewDataSource to realize, each card is a CollectionViewCell;

2) requires Collection View in the Scroll Direction set to a horizontal scroll;

3) review of the use of Visual Effect View, has been embedded into the ImageView to do clipsToBounds;

Project 6 – Get current user’s location

Self-learning iOS - thirty days thirty Swift projects

1) first obtain location permissions, the need to increase the NSLocationAlwaysUsageDescription in the info.plist (input to inform the user why use geographical location permissions) and NSLocationWhenInUseUsageDescription;

2) import CoreLocation Framework, the use of CLLocationManagerDelegate in the CLPlacemark to get the city, province and country, in fact, also need areasOfInterest, but do not know why not effective;

Project 7 – Pull Refresh and load data To

Self-learning iOS - thirty days thirty Swift projects

1) UIRefreshController to achieve the drop-down refresh, you can change the background color, chrysanthemum color, text color and size, attributedTitle font color plagued me for a long time, using the following ways to achieve:

Let attributes = [NSForegroundColorAttributeName:UIColor.whiteColor (
)] self.refreshControl.attributedTitle = NSAttributedString (“string: Last updated on/ (NSDate) (attributes:), attributes)

2)这次 tableView 都是用代码实现的,所以看过去 Y 轴的位置没有居于 UINavigationBar 之下,但是no-storyboarding 的好处就是学会了 tableView 的很多属性,其实跟 sb 也差不多,对于习惯的人来说确实也非常快,怪不得我之前认识的胖子一直是用代码写 UI,极少用sb;

3 refreshControl in the addTarget can do forControlEvents:.ValueChanged, so that I can pull down when the refresh of the second groups of data loaded out, This’s it!

4) write UINavigationBar code can not set title ah, topItem, or navigationbarItem have tried;

Project 8 – Random Color Gradient

Self-learning iOS - thirty days thirty Swift projects

1) I would like to do after a App can “beat” listen to music beats to the outside of the screen background color, so that dozens of mobile phone together together, will feel very shocked, but I’m not so strong to develop this kind of application, so the first random transform to achieve background color gradient, of course insert background music, not just “listening” function, to compare the effect of magic;

2) learn to use CAGradientLayer to do the background gradient, the gradient is divided into two layers, one layer after determines the whole effect of why the color will change, in front of a layer is to set the gradient color, position and startPoint endPoint;

3) after the realization of the principle is a random change of pure color can be assigned to the RGB tricolor, such as redValue = CGFloat (drand48)), so that the background color can be randomly changed in 256 colors;

Project 9 – Image Scroller

Self-learning iOS - thirty days thirty Swift projects

1) zoom in and out of the horizontal vertical scroll to view the larger picture, similar to the effect of the same picture in the iMessage view;

2) first set of UIImageView to UIScrollView, in setZoomScaleFor (srollViewSize:CGSize), the maximum scaling refers to the original 3 times;

3) back to the center of the initial interface, recenterImage ();

Project 10 – Video Background

Self-learning iOS - thirty days thirty Swift projects

1) a cool and not a lot of video as a background element of the Splash interface, is enough to make users feel the first time to the scene and the application value of Spotify is a good example, which uses the material is from Spotify for iOS;

2) this is the use of a custom VC: VideoSplashViewController, you can easily use the AVPlayerViewController thing;

3) fillMode =.ResizeAspectFill, then is always loop: alwaysRepeat=true;

4) always remember the video file to copy to bundle resources;

Project 11 – Clear TableViewCell Prioritize

Self-learning iOS - thirty days thirty Swift projects

1) Clear App interface and interaction is very amazing, has been amazing for several years, so this is to achieve a gradient color TableView, of course, not only monochrome, also increased the gradient in cell;

2) use the following methods to achieve gradient:

Func colorforIndex (index:Int) -> UIColor
let {itemCount = tableData.count – 1 let (color = CGFloat (index) / CGFloat (itemCount)) * 0.6 return (red:1.0 UIColor, green: color, blue:0.0, alpha:1.0)}

3) in the code directly removed the tableview partition line and hide the selected color click cell:

Self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None cell.selectionStyle = UITableViewCellSelectionStyle.None =

Project 12 – Simple Login Animation

Self-learning iOS - thirty days thirty Swift projects

1) started to learn the iOS animation, see the basic elastic view animation, Spring animation, key frame animation and view transformation, all is really interesting, because I used Principle to do when the prototype design is used only after these things, does not know how to achieve code, of course, now has just begun. Contact, so learn to write a login interface transition animation, click the Login button on the bounds.size.width+60 has been widened out on behalf of self.loginButton.enabled=false;

2)viewWillAppear 先设定好2个 UITextField Center.X 约束的初始值,然后才在 viewDidAppear里写 UIView.animateWithDuration(_:, delay:, options:, animations:, completion:),这应该是写动画的过程;

3) Tips: can not change the height of the beginning of the UITextField, and later is a way to use constraints to achieve Update Frames;

Project 13 – Animate TableViewCell

Self-learning iOS - thirty days thirty Swift projects

1 TableViewController between the TableViewCell animation, TableViewCell gradient gradient between the use of the code in the Project-11;

2) tableView is a visibleCells, so that you can not let the Cells before loading, and then to the bottom of the interface and then loaded up;

3) this is the use of Spring animation to achieve such an elastic effect: usingSpringWithDamping:0.8, initialSpringVelocity:0, in fact, is a very basic animation;

Project 14 – Emoji Slot Machine

Self-learning iOS - thirty days thirty Swift projects

1) today is mainly for Build for fun, using UIPickerView to achieve the Emoji slot machine games;

2) (arc4random) (random) random row Emoji, three rows of three Emoji;

3)如果第一列的 Emoji == 第二列 && 第二列 == 第三列,那么就会出现 Bingo!的结果,反之都是?,GIF演示中的 resultLabel layout 不太对,后来修复了,因为要重新录到三个一样其实概率还是很低的,当然这个概率是可以设定的;

4) click on the UIButton animation effect is also completed after the show did not appear in the GIF;

5 to share a quick input Emoji MacOS tips: press Control + Command + space bar on it;

Project 15 –  Animated Splash

Self-learning iOS - thirty days thirty Swift projects

1) Twitter startup animation has been a classic, the birds Logo stay in the center and then zoom out with the entire interface, is a pleasant process;

2 (View) LaunchScreen.storyboard set a good blue background and put the Twitter bird figure, the code is written in AppDelegate;

3) is different from the original Twitter App animation, this is the bird as a Mask to use, with CAKeyframeAnimation, set the value of the 3 Bounds, the transition can be achieved amplification animation.

Let initalBounds =NSValue (CGRect:mask.Bounds
let!) secondBounds =NSValue (CGRect:CGRect (x:0, y:0, width:90, height:73) let finalBounds =NSValue (CGRect:CGRect) (x:0, y:0, width:1600, height:1300))

Project 16 – Slide Menu Transition

Self-learning iOS - thirty days thirty Swift projects

1) without the use of special three bars of Hamburger icon, but I used a Emoji to do burger menu icon):

2) 2 VC, Segue to do with self transitions, MenuTransitionManagerDelegate protocol is introduced in the first VC, moveDown to container!.frame.height -150 in this position, select the Menu after second VC moveUp to the -50 position;

3) increase UITapGestureRecognizer, you can click on the non MenuTableViewCell part can also be dismiss;

Project 17 – Tumblr Menu

Self-learning iOS - thirty days thirty Swift projects

1 this is the old version of the iOS Tumblr to create a new Post transition animation, the new version has a more dazzling new animation;

2) with Project 16 is also the same as the 2 VC, the realization of the 1 MenuTransitionManager, it seems that this is the realization of the transition between VC animation (while retaining the previous layer VC) of the “standard way”?

3) even 13 IBOutlet is drunk, because icons and text can press the Delay time when there are different, the introduction of UIViewControllerTransitioningDelegate in MenuTransitionManager to achieve animation, including the first VC with transparent background blur;

4) Menu is divided into three groups, set the topRowOffset middleRowOffset bottomRowOffset were CGFloat 30015050, so Text at transform and Photo self.offstage (-topRowOffset) and self.offstage (topRowOffset) which in turn corresponds, these 2 groups of the same;

5) but I do not know if it is added to the background of the relationship between the Effect View Visual, the feeling will flash a look, has not found a way to solve;

Project 18 – Limit Character

Self-learning iOS - thirty days thirty Swift projects

1) define the UITextView input characters, with micro-blog Twitter to do the 140 word limit, then you cannot lose move, first try UITextField, that can not line, fart ah, change to UITextView;

2) at the bottom of a row of UIView in viewDidLoad () to do a 2 NSNotificationCenter, notification with the keyboard up and dismiss;

3) to achieve the input character limit by using the shouldChangeTextInRange method in the UITextViewDelegate, if range.length > 140 input is not available, the real-time character right small angle is the penultimate “(140- / myTextViewString.characters.count) to achieve;

4) UI Copy from the third party Twitter client Twitterrific;

Project 19 – Custom Pull-To-Refresh

Self-learning iOS - thirty days thirty Swift projects

1) at Project 7 when I made the pull-down refresh and loading data, but the drop-down refresh style or system of chrysanthemum style, so try to customize the drop-down refresh, with a simple animation single text color rotation and zoom;

2 new RefreshContents.xib dedicated to refresh the 12 UILabels, do not connect to the ViewController, with viewWithTag () to specify;

3) refresh animation is divided into two steps, so the 2 step approach of the building, animateRefreshStep1 () and animateRefreshStep2 (CGAffineTransformMakeRotation), the first step is to rotate (CGFloat (M_PI_4)) and textColor (self.getNextColor) random color (this is a new method of random color), the second step is to do more simple amplification animation, all Scale to CGAffineTransformMakeScale (1.5,1.5);

4) because there is no real data relationship, this small test is to use NSTimer.scheduledTimerWithTimeInterval to stabilize the effect of 5 seconds to do, the real project is certainly not this;

Project 20 – UICollectionView Animation

Self-learning iOS - thirty days thirty Swift projects

1) ah, this effect is actually very bad, but the smooth transitions UICollectionView we should often see, especially between List and Details, such as the list of goods and goods details, list of news and news text;

2) this is actually a VC, details of the interface in more than just a return to icon, click didSelectItemAtIndexPath collectionView in func after the implementation of the transition, to bring Cell to the top level of cell?.superview?.bringSubviewToFront (cell!), and then cell?.frame= collectionView.bounds can change to full screen, through this example also help I understand the difference between frame and bounds;

3) in func backButtonDidTouch () remember to let CollectionView reloadItemsAtIndexPaths;

Project 21 – Swipeable Cell

Self-learning iOS - thirty days thirty Swift projects

1) sliding Cell related operations this interactive application is the most classic Mailbox show that, after the iOS 7 also introduced a system of sliding Cell interaction, so can be directly in the tableView editActionsForRowAtIndexPath execution UITableViewRowAction;

2) iOS in the design proposal is used to display text, but we can also be more vivid with icons and text, but Google still can not find a circle purely with custom icon to replace, so only in Riga Title Emoji and a space to achieve, do not know what people see good method;

Let delete = UITableViewRowAction (style:.Normal, title: “/nDelete”) {action, indexin}

3) click on the sharing of the operation of the system to share control, is a simple UIActivityViewController can do;

Project 22 – 3D Quick Touch Action

Self-learning iOS - thirty days thirty Swift projects

1) 3D Touch is a shortcut to start in the info.plist UIApplicationShortcutItems configuration, as shown in the following figure, I were equipped with what I want most 3 shortcut, in the setting of App switch WiFI, quick start running in the NikePlus, the camera to scan two-dimensional code;

Self-learning iOS - thirty days thirty Swift projects

2) UIApplicationShortcutItemIconFile is configured custom icon, UIApplicationShortcutItemTitle configuration quick name, of course, you can configure the title two;

3) select the shortcut to enter the corresponding VC;

Window!.rootViewController?.presentViewController (VC, animated:true, completion:nil)

Project 23 – Slide Out Menu

Self-learning iOS - thirty days thirty Swift projects

1) gesture sideslip menu switching between VC, using the SWRevealViewController open source project, which makes it all too simple too much;

2) out of the side of the TableViewController inherited the RevealViewController, and then in each of the VC ViewDidLoad () in the following code can be a sign of sideslip;

Self.view.addGestureRecognizer (self.revealViewController) (.PanGestureRecognizer) (

Project 24 – Mosaic Layouts

Self-learning iOS - thirty days thirty Swift projects

1 mosaic photo layout can adjust the number of photos per line, etc., with the open source FMMosaicLayout;

2) learned to use Terminal to install Pod, the use of open source projects;

Self-learning iOS - thirty days thirty Swift projects

3) the entire layout is evident in UICollectionView, FMMosaicLayout supports computable size changes;

Return indexPath.item% 7 = = 0? FMMosaicCellSize.Big: FMMosaicCellSize.Small

Project 25 – UIView Basic Animations

Self-learning iOS - thirty days thirty Swift projects

1) return to learn animation most basic things today, including Position, Opacity, Scale, Color, Rotation, no matter how cool more complex animation is sum of these foundations, this example in the animation are written in viewDidAppear (in);

2) Position: 3 UIView position and the height of the change made a -_- expression;

3) Opacity: change ImageView alpha can;

4) Scale: beginning in the SB a little bit, and then perform zoom Spring animation to CGAffineTransformMakeScale (2,2), obviously alpha is from 0 to 1 will be more harmonious;

5) Color: change UIView and Label textcolor can;

6) Rotation: this is a little fun, can draw the spin of the roulette wheel, wrote a new func spin (CGAffineTransformRotate), at the time of transform (self.rotationImageView.transform, CGFloat (M_PI)), then add self.spin in complete animation () can keep rotating, or will only perform a selection time;

Project 26 – CoreData App

Self-learning iOS - thirty days thirty Swift projects

1) CoreData is still cool stuff, although it is not quite understood, seemingly can replace the database;

2) this CoreData based To App can add a new To-do, delete and then open the next back or the same as before after the deletion of the Do;

(3) the need to build a new entity ListEntity, and the new item: String property in the Coredata file;

4 remember to create a project or a single file must check CoreDada;

Project 27 – Tab Bar Switch

Self-learning iOS - thirty days thirty Swift projects

1) in the Storyboard arrangement can realize the most basic interactive information architecture of a complete App with TabbarController plus NavigationController and App, many data show that Tabbar navigation mode at the bottom than the sideslip or Android at the top of the navigation allows users to accept, almost do not need to write a line of code can be achieved;

2) in order to make the results more close to a App, the first Tab is added to the dynamic Spring effect of the TableViewCell, and behind the two Tab is false, only UIImageView;

Project 28 – Spotlight Search

Self-learning iOS - thirty days thirty Swift projects

1) after iOS 8 can support the search for the third party application data in iOS Spotlight, in order to do your data in the App searchable, will have to first create a MoviesData.plist configuration data attribute;

Self-learning iOS - thirty days thirty Swift projects

2) in the project – General – Frameworks and Libraries add CoreSpotlight and MobileCoreServices framework, so you can use the properties of the CSSearchableItem;

3) in the Spotlight interface is also similar to custom drop-down refresh the new xib;

Project 29 – iMessage Image Picker

Self-learning iOS - thirty days thirty Swift projects

1) when registered in the App add an avatar is often a necessary step, most people choose a picture directly from the album, so in order to facilitate the rapid selection of images from the album to use the iMessage interactive send photos would be a good choice;

2) with Tap Gesture Recognizer in the default avatar, the method call on this album Tap method also need to write, import Photos, of course, do iMessage interaction is more complex, directly used the open source project ImagePickerSheetController;

Project 30 – WiKiFace

Self-learning iOS - thirty days thirty Swift projects

1) WiKiFace are a fully functional Tiny App, because the function is to help you search the celebrity names, to face part of Wikipedia’s thumbnail in the use of the Wikipedia API, and ImageIO in CIFaceFeature;

Self-learning iOS - thirty days thirty Swift projects

2 (func) (textFieldShouldReturn) in the implementation of the name of the input after the transfer of API in the photo try WikiFace.faceForPerson, WikiFace.swfit transferred to the picture, you need to identify the face and the center of the photo;

3 Is it cool?


No one should see it here? Because the Spring Festival holiday and home network is not very good relationship, the article is now sorted out (finishing the process is also a review code). The past 30 days every day out of time to write a little code, this is the first year to adhere to the completion of the challenge of the 30 day plan, the next will continue to see more Swift basis and then do a APP. I spent most of my time is synchronous Project schedule information in Twitter / Instagram / Dribbble and Facebook, interested people can pay attention to:)