Getting started with iOS
UILabel
Change Status Bar Color
Passing Data between View Controllers
Managing the Keyboard
UIButton
UILocalNotification
UIImageView
Checking for Network Connectivity
Accessibility
UITableView
Auto Layout
UIView
UIAlertController
MKMapView
UIColor
NSAttributedString
CAAnimation
UITextView
UINavigationController
Concurrency
CAGradientLayer
UIGestureRecognizer
Custom UIViews from XIB files
Safari Services
UIStackView
UIImage
UIWebView
CALayer
Swift and Objective-C interoperability
NSDate
Custom Fonts
AVSpeechSynthesizer
UIBarButtonItem
UIScrollView
Localization
NSNotificationCenter
UITextField
Networking with Alamofire
UIViewController
iBeacon
CLLocation
NSURLSession
UISwitch
Checking iOS version
Universal Links
UICollectionView
PDF Creation
In-App Purchase
NSTimer
CGContext
UITabBarController
UISearchController
UIActivityViewController
Core Location
FacebookSDK
AFNetworking
CTCallCenter
UIImagePickerController
NSUserDefaults
UIControl - Event Handling with Blocks
UIBezierPath
UIPageViewController
UIAppearance
Push Notifications
Key Value Coding
Initialization idioms
Storyboard
Background Modes and Events
Fastlane
CAShapeLayer
WKWebView
UUID Universally Unique Identifier
Categories
Handling URL Schemes
Realm database
ARC Automatic Reference Counting
UIPickerView
Dynamic Type
NSURL
SWRevealViewController
Snapshot of UIView
DispatchGroup
GCD Grand Central Dispatch
Size Classes and Adaptivity
UIScrollView, AutoLayout
IBOutlets
AWS SDK
Debugging Crashes
UISplitViewController
UISplitViewController
UIDevice
CloudKit
GameplayKit
XCode Build Archive From Command Line
Unit Testing with XCTest
NSData
AVPlayer and AVPlayerViewController
Deep Linking
App Transport Security (ATS)
Core Graphics
Segues
UIDatePicker
NSPredicate
EventKit
NSBundle
SiriKit
Contacts Framework
Dynamically updating a UIStackView
Speech Recognition
NSURLConnection
StoreKit
Code signing
.ipa file to upload on appstore with ApplicationLoader
Resizing UIImage
Size Classes and Adaptivity
MKDistanceFormatter
3D Touch
GameCenter Leaderboards
Keychain
Handle Multiple Environment using Macro
Set View Background
Block
Content Hugging
Google Places API
Navigation Bar
UITextField Delegate
App-wide operations
UILabel text underlining
Cut a UIImage into a circle
Make selective UIView corners rounded
Convert HTML to NSAttributed string and vice versa
Convert NSAttributedString to UIImage
CoreImage Filters
Face Detection Using CoreImageOpenCV
MPMediaPickerDelegate
Graph Coreplot
NSHTTPCookieStorage
FCM Messaging
Create Custom Framework
Custom Keyboard
AirDrop
SLComposeViewController
AirPrint tutorial
UISlider
Carthage
HealthKit
Core SpotLight
UI Testing
Core Motion
QR Code Scanner
plist
NSInvocation
UIRefreshControl TableView
WCSessionDelegate
AppDelegate
App Submission Process
MVVM
UIStoryboard
Basic text file I/O
Text To Speech (TTS)
MPVolumeView
Objective-C Associated Objects
Passing Data between View Controllers
UIPhoenix
Blocks in Queue with MKBlockQueue
Simulator
BackgroundModes
NSArray
OpenGL
UIScrollView with StackView child
Cache online images
MVP Architecture
UIKit Dynamics
Configure Beacons with CoreBluetooth
Core Data
Extension for rich Push Notification
Profiling with Instruments
Application rating review request
MyLayout
UIFont
Simulator Builds
Simulating Location Using GPX files
Custom methods of selection of UITableViewCells
Custom methods of selection of UITableViewCells
UISegmentedControl
SqlCipher integration
Custom UITextField
Custom UITextField
Security
Guideline to architecture patterns
UIFeedbackGenerator
UIKit Dynamics with UICollectionView
Multicast Delegates
Using image assets
UITableViewCell
Runtime in Objective-C
ModelPresentationStyles
CydiaSubstrate tweak
Create a video from images
Codable
FileHandle
NSUserActivity
Rich Notifications
Load images async
Adding Swift bridging header
Creating an App ID
Changing the rootview controller
Attributed text in UILabel
UITableViewController
Contributors

AirPrint printing Banner Text

suggest change

Objective-C

Add the delegate and a text-formatter to the ViewController.h file

@interface ViewController : UIViewController <UIPrintInteractionControllerDelegate> {
    UISimpleTextPrintFormatter *_textFormatter;
}

In the ViewController.m file define the following constants

#define DefaultFontSize 48
#define PaddingFactor 0.1f

The function which prints the text is as follows:-

-(IBAction)print:(id)sender;
{
    /* Get the UIPrintInteractionController, which is a shared object */
    UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
    if(!controller){
        NSLog(@"Couldn't get shared UIPrintInteractionController!");
        return;
    }
    
    /* Set this object as delegate so you can  use the printInteractionController:cutLengthForPaper: delegate */
    controller.delegate = self;
        
    UIPrintInfo *printInfo = [UIPrintInfo printInfo];
    printInfo.outputType = UIPrintInfoOutputGeneral;

    /* Use landscape orientation for a banner so the text  print along the long side of the paper. */
    printInfo.orientation = UIPrintInfoOrientationLandscape;

    printInfo.jobName = self.textField.text;
    controller.printInfo = printInfo;
    
    /* Create the UISimpleTextPrintFormatter with the text supplied by the user in the text field */
    _textFormatter = [[UISimpleTextPrintFormatter alloc] initWithText:self.textField.text];
    
    /* Set the text formatter's color and font properties based on what the user chose */
    _textFormatter.color = [self chosenColor];
    _textFormatter.font = [self chosenFontWithSize:DefaultFontSize];
    
    /* Set this UISimpleTextPrintFormatter on the controller */
    controller.printFormatter = _textFormatter;
    
    /* Set up a completion handler block.  If the print job has an error before spooling, this is where it's handled. */
    void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
        if(completed && error)
            NSLog( @"Printing failed due to error in domain %@ with error code %lu. Localized description: %@, and failure reason: %@", error.domain, (long)error.code, error.localizedDescription, error.localizedFailureReason );
    };

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        [controller presentFromRect:self.printButton.frame inView:self.view animated:YES completionHandler:completionHandler];
    else
        [controller presentAnimated:YES completionHandler:completionHandler];  // iPhone
}

The delegate function which sets up the print page:-

- (CGFloat)printInteractionController:(UIPrintInteractionController *)printInteractionController cutLengthForPaper:(UIPrintPaper *)paper {

    /* Create a font with arbitrary size so that you can calculate the approximate
        font points per screen point for the height of the text. */
    UIFont *font = _textFormatter.font;
    CGSize size = [self.textField.text sizeWithAttributes:@{NSFontAttributeName: font}];
    
    float approximateFontPointPerScreenPoint = font.pointSize / size.height;
    
    /* Create a new font using a size  that will fill the width of the paper */
    font = [self chosenFontWithSize: paper.printableRect.size.width * approximateFontPointPerScreenPoint];
    
    /* Calculate the height and width of the text with the final font size */
    CGSize finalTextSize = [self.textField.text sizeWithAttributes:@{NSFontAttributeName: font}];
    
    /* Set the UISimpleTextFormatter font to the font with the size calculated */
    _textFormatter.font = font;
    
    /* Calculate the margins of the roll. Roll printers may have unprintable areas
        before and after the cut.  We must add this to our cut length to ensure the
        printable area has enough room for our text. */
    CGFloat lengthOfMargins = paper.paperSize.height - paper.printableRect.size.height;

    /* The cut length is the width of the text, plus margins, plus some padding */
    return finalTextSize.width + lengthOfMargins + paper.printableRect.size.width * PaddingFactor;
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents