Latest | 0.0.1 |
---|---|
Homepage | https://github.com/liuxc123/GTFInternationalization |
License | MIT |
Platforms | ios 8.0, requires ARC |
Authors |
Right-to-Left calculations for CGRects and UIEdgeInsets
A UIView is positioned within its superview in terms of a frame (CGRect) consisting of an
origin and a size. When a device is set to a language that is written from Right-to-Left (RTL),
we often want to mirror the interface around the vertical axis. This library contains
functions to assist in modifying frames and edge insets for RTL.
// To flip a subview's frame horizontally, pass in subview.frame and the width of its parent.
CGRect originalFrame = childView.frame;
CGRect flippedFrame = GTFRectFlippedHorizontally(originalFrame, CGRectGetWidth(self.bounds));
childView.frame = flippedFrame;
Mirroring Images
A category on UIImage backports iOS 10’s [UIImage imageWithHorizontallyFlippedOrientation]
to
earlier versions of iOS.
// To mirror on image, invoke gtf_imageWithHorizontallyFlippedOrientation.
UIImage *mirroredImage = [originalImage gtf_imageWithHorizontallyFlippedOrientation];
Adding semantic context
A category on UIView backports iOS 9’s -[UIView semanticContentAttribute]
and iOS 10’s
-[UIView effectiveUserInterfaceLayoutDirection]
to earlier versions of iOS.
// To set a semantic content attribute, set the gtf_semanticContentAttribute property.
lockedLTRView.gtf_semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
// gtf_semanticContentAttribute is used to calculate the gtf_effectiveUserInterfaceLayoutDirection
if (customView.gtf_effectiveUserInterfaceLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeft) {
// Update customView's layout to be in RTL mode.
}
Embedding Bidirection strings
A category on NSString offers a simple API to wrap strings in Unicode markers so that LTR
and RTL text can co-exist in the same string.
// To embed an RTL string in an existing LTR string we should wrap it in Unicode directionality
// markers to maintain preoper rendering.
// The name of a restaurant is in Arabic or Hebrew script, but the rest of string is in Latin.
NSString *wrappedRestaurantName =
[restaurantName gtf_stringWithStereoReset:NSLocaleLanguageDirectionRightToLeft
context:NSLocaleLanguageDirectionLeftToRight];
NSString *reservationString = [NSString stringWithFormat:@"%@ : %ld", wrappedRestaurantName, attendees];
Usage
See Example for a detailed example of how to use the functionality provided by this library.
Installation
GTFInternationalization is available through CocoaPods. To install
it, simply add the following line to your Podfile:
pod 'GTFInternationalization'
Author
liuxc123, [email protected]
License
GTFInternationalization is available under the MIT license. See the LICENSE file for more info.
Latest podspec
{ "name": "GTFInternationalization", "version": "0.0.1", "summary": "Internationalization tools.", "homepage": "https://github.com/liuxc123/GTFInternationalization", "license": { "type": "MIT", "file": "LICENSE" }, "authors": { "liuxc123": "[email protected]" }, "source": { "git": "https://github.com/liuxc123/GTFInternationalization.git", "tag": "0.0.1" }, "platforms": { "ios": "8.0" }, "requires_arc": true, "public_header_files": "src/*.h", "source_files": "src/*.{h,m}", "header_mappings_dir": "src", "header_dir": "GTFInternationalization" }
Wed, 22 Aug 2018 14:40:04 +0000