Nơi niềm đam mê bắt đầu=> Swift ...

abtranbn
19/2/2015 7:13Phản hồi: 94
Nơi niềm đam mê bắt đầu=> Swift ...
94 bình luận
Chia sẻ

Xu hướng

abtranbn
TÍCH CỰC
9 năm
How do I hide the status bar in a Swift iOS app?
Code:
override func prefersStatusBarHidden() -> Bool {
return true
}
hoặc:Trong Info.plist thiết lập View controller-based status bar appearance là NO
thêm:
Code:
UIApplication.sharedApplication().statusBarHidden = true
objectiveC:
Code:
- (BOOL)prefersStatusBarHidden
{
    return YES;
}
abtranbn
TÍCH CỰC
9 năm
Share Facebook....
Code:
func showFaceBook() {
let facebook = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
facebook.completionHandler = {
result in
switch result {
case SLComposeViewControllerResult.Cancelled:
//Add code to deal with it being cancelled
break

case SLComposeViewControllerResult.Done:
//Add code here to deal with it being completed
//Remember that dimissing the view is done for you, and sending the tweet to social media is automatic too. You could use this to give in game rewards?
break
}
}
abtranbn
TÍCH CỰC
9 năm
high score:

Code:
var highScoretg : NSNumber? = NSUserDefaults.standardUserDefaults().integerForKey("highscore")
heightScoreLable = UILabel(frame: CGRect(x:0, y:0, width:200, height:50))
// NSLog("\(hightScore!)")
heightScoreLable?.text = "HIGH SCORE:" + highScoretg!.stringValue
heightScoreLable?.textAlignment = NSTextAlignment.Center
heightScoreLable?.textColor = UIColor(red: 1, green: 0, blue: 0, alpha: 1)
self.view.addSubview(heightScoreLable!)
heightScoreLable?.center.x = self.view.bounds.size.width/2
heightScoreLable?.center.y = 50
======> scoreLabel!.text = "SCORE:" + score!.stringValue
abtranbn
TÍCH CỰC
9 năm
Rung Rung Rung!
Code:
import UIKit
import AudioToolbox

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

      AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))

    }
}
http://stackoverflow.com/questions/26455880/how-to-make-iphone-vibrate-using-swift
abtranbn
TÍCH CỰC
9 năm
lỗi biên dịch chậm ở BootLogic.swift, cần khai báo tường minh NSDictionary
Code:
class func boot(window:UIWindow){
let mainScreen = MainScreen(style: UITableViewStyle.Grouped)
var simpleIO = [SECTION: "Simple IO",MENU:[
[TITLE: "Read from plist",CLASS: "ReadPlist"],
[TITLE: "Write to plist",CLASS: "WritePlist"],
[TITLE: "Read/Write NSUserDefaults",CLASS: "ReadWriteNSUserDefaults#Storyboard"],
[TITLE: "NSCoding",CLASS: "NSCodingDemo"],
[TITLE: "Key Value Observer (KVO)",CLASS: "KVODemo"],
[TITLE: "Notification Center",CLASS: "NotificationDemo"]
]
] as NSDictionary //Cuong: must explicitly declare as NSDictionary to speed up compiling
abtranbn
TÍCH CỰC
9 năm
UITableViewCell Selected Background Color on Multiple Selection:
Code:
override func viewDidLoad() {

        super.viewDidLoad()

        tableView.backgroundColor = UIColor(red: 50, green: 10, blue: 100, alpha: 0.4)
}
abtranbn
TÍCH CỰC
9 năm
abtranbn
TÍCH CỰC
9 năm
Login facebook (using sdk facebook - swift) :
Code:
-#import <FacebookSDK/FacebookSDK.h> to file brigh.h
-thêm vô appledelegate.swift: (trong didFinishLaunchingWithOptions)

Code:
FBLoginView.self
        FBProfilePictureView.self
-thêm vô func:

Code:
func application(application: UIApplication, openURL url: NSURL, sourceApplication: NSString?, annotation: AnyObject) -> Bool {
  
        var wasHandled:Bool = FBAppCall.handleOpenURL(url, sourceApplication: sourceApplication)
        return wasHandled
  
    }
- Them vô file .plist của project:

Code:
<key>FacebookDisplayName</key>
    <string>Snake 2025</string>
    <key>FacebookAppID</key>
    <string>1553157654954418</string>
    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>fb1553157654954418</string>
            </array>
        </dict>
    </array>
- thêm vô file swift chính delegate của facebook:
Code:
class LogicalView: UIViewController, STADelegateProtocol,FBLoginViewDelegate {
...
-thêm vô: button (cả mainstoryboard)
Code:
@IBOutlet var fbLoginView: FBLoginView!
- tiếp tục trong viewdidload thêm 2 dòng sau:

Code:
self.fbLoginView?.delegate = self
        self.fbLoginView?.readPermissions = ["public_profile", "email", "user_friends"]
- thêm các func này là xong:

Code:
func loginViewShowingLoggedInUser(loginView : FBLoginView!) {
        println("User Logged In")
        println("This is where you perform a segue.")
    }

    func loginViewFetchedUserInfo(loginView : FBLoginView!, user: FBGraphUser){
        println("User Name: \(user.name)")
    }

    func loginViewShowingLoggedOutUser(loginView : FBLoginView!) {
        println("User Logged Out")
    }

    func loginView(loginView : FBLoginView!, handleError:NSError) {
        println("Error: \(handleError.localizedDescription)")
    }
abtranbn
TÍCH CỰC
9 năm
Share Tweeter:
Code:
func showTweetSheet() {

        let tweetSheet = SLComposeViewController(forServiceType: SLServiceTypeTwitter)

        tweetSheet.completionHandler = {

            result in

            switch result {

            case SLComposeViewControllerResult.Cancelled:

                //Add code to deal with it being cancelled

                self.showResult()

             

            case SLComposeViewControllerResult.Done:

                //Add code here to deal with it being completed

                //Remember that dimissing the view is done for you, and sending the tweet to social media is automatic too. You could use this to give in game rewards?

                self.showResult()

            }

        }

     

        tweetSheet.setInitialText("Oh my god! Score in game \"Snake 2025\" is \(score!.stringValue).") //The default text in the tweet

        tweetSheet.addImage(self.screenShotMethod()) //Add an image if you like?

        tweetSheet.addURL(NSURL(string: "https://twitter.com/mhtranbn")) //A url which takes you into safari if tapped on

     

        self.presentViewController(tweetSheet, animated: false, completion: {

            //Optional completion statement

        })

    }
abtranbn
TÍCH CỰC
9 năm
abtranbn
TÍCH CỰC
9 năm
ads by Apple (ObjtiveC):
add : to
Code:
#import <iAd/iAd.h>
add them vo
Code:
<..., ADBannerViewDelegate>
vo View

add vo ViewColtroler
Code:
#pragma mark iAD

Code:
- (void)bannerViewDidLoadAd😔ADBannerView *)banner {

    [UIViewbeginAnimations:nilcontext:nil];

    [UIViewsetAnimationDuration:1];

    [banner setAlpha:1];

    [UIViewcommitAnimations];

}



-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {

    [UIViewbeginAnimations:nilcontext:nil];

    [UIViewsetAnimationDuration:1];

    [banner setAlpha:0];

    [UIViewcommitAnimations];

}
abtranbn
TÍCH CỰC
9 năm
Rates your app when it not in appstore:


Code:
func touchMyApp(){
        var url:NSURL? = NSURL(string: "itms-apps://itunes.apple.com/app/id966430xxx")
        UIApplication.sharedApplication().openURL(url!)
}
abtranbn
TÍCH CỰC
9 năm
bo tròn các icon như sau:
Code:
image.layer.borderWidth=1.0
image.layer.masksToBounds =false
image.layer.borderColor =UIColor.whiteColor().CGColor
image.layer.cornerRadius =13
image.layer.cornerRadius = image.frame.size.height/2
image.clipsToBounds =true
abtranbn
TÍCH CỰC
9 năm
Mail chèn vô: Send and Cancel Alert:
Code:
-(void)emailSendComplete😔MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{

 

    switch (result)

    {

        caseMFMailComposeResultCancelled:

            //NSLog(@"Result: canceled");

            break;

        caseMFMailComposeResultSaved:

            //NSLog(@"Result: saved");

            break;

        caseMFMailComposeResultSent:

        {

            UIAlertView *alert = [[UIAlertViewalloc]

                                                            initWithTitle: @"Email"

                                                            message: @"Thanks for your feeback!"

                                                            delegate: self

                                                            cancelButtonTitle: @"OK"

                                                            otherButtonTitles: nil];

            [alert show];

         

        }

            break;

        caseMFMailComposeResultFailed:

            //NSLog(@"Result: failed");

            break;

        default:

            //NSLog(@"Result: not sent");

            break;

    }

    [selfdismissModalViewControllerAnimated:YES];

}

// Called when an alertview button is clicked

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

    switch (alertView.tag) {

            switch (buttonIndex) {

                case 0: // cancel

                {

                    dispatch_async(dispatch_get_main_queue(), ^{

                        [selfdismissModalViewControllerAnimated:YES];

                    });

                 

                }

                    break;

                case 1:

                {

                    //[self saveToDirectory];

                 

                }

                    break;

            }

         

    }

}
abtranbn
TÍCH CỰC
9 năm
Hidden keyboarch objectiveC:
vô viewdidload thêm:
Code:
//Add tapGesture

    self.tapGesture = [[UITapGestureRecognizeralloc] initWithTarget:selfaction:mad:selector(actionHideKeyboard😃];

    [self.viewaddGestureRecognizer:self.tapGesture];
thêm func:
Code:
- (void)actionHideKeyboard😔UITapGestureRecognizer *)tapGesture{

    [self.txtCommentsresignFirstResponder];

}
abtranbn
TÍCH CỰC
9 năm
Khởi tạo data trong Bundle:
Code:
var data : NSArray?
var dataFile: NSString = NSBundle.mainBundle().pathForResource("data", ofType: "plist", inDirectory: nil)!
 data = NSArray(contentsOfFile: dataFile)

Xu hướng

Bài mới









  • Chịu trách nhiệm nội dung: Trần Mạnh Hiệp
  • © 2024 Công ty Cổ phần MXH Tinh Tế
  • Địa chỉ: Số 70 Bà Huyện Thanh Quan, P. Võ Thị Sáu, Quận 3, TPHCM
  • Số điện thoại: 02822460095
  • MST: 0313255119
  • Giấy phép thiết lập MXH số 11/GP-BTTTT, Ký ngày: 08/01/2019